Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot handle this data type #108

Closed
usasho opened this issue Aug 22, 2018 · 10 comments
Closed

TypeError: Cannot handle this data type #108

usasho opened this issue Aug 22, 2018 · 10 comments

Comments

@usasho
Copy link

usasho commented Aug 22, 2018

6it [00:09, 1.66s/it]
Loss: 1.4190080761909485
4it [00:06, 1.57s/it]Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2150, in fromarray
mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 75), '|u1')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "https://t.co/oY6LXrEgZv", line 983, in
train_seq2seq=train_seq2seq, train_postnet=train_postnet)
File "https://t.co/oY6LXrEgZv", line 717, in train
eval_model(global_step, writer, device, model, checkpoint_dir, ismultispeaker)
File "https://t.co/oY6LXrEgZv", line 414, in eval_model
writer.add_image(tag, np.uint8(cm.viridis(np.flip(alignment, 1).T) * 255), global_step)
File "/usr/local/lib/python3.5/dist-packages/tensorboardX/writer.py", line 412, in add_image
self.file_writer.add_summary(image(tag, img_tensor), global_step, walltime)
File "/usr/local/lib/python3.5/dist-packages/tensorboardX/summary.py", line 205, in image
image = make_image(tensor, rescale=rescale)
File "/usr/local/lib/python3.5/dist-packages/tensorboardX/summary.py", line 243, in make_image
image = Image.fromarray(tensor)
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2153, in fromarray
raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type

@usasho
Copy link
Author

usasho commented Aug 22, 2018

上げました
Pillow系のerrorだとは思うのですが、
解決策が無いため、質問させて頂きました

@usasho
Copy link
Author

usasho commented Aug 24, 2018

Torchのバージョンもあるかもしれません、
古いlinuxなら動きましたので、
Dtypeの記述が逆なのかもしれませんね
KeyError: ((1, 1, 75), '|u1')
Torch 0.4.1から色々変わってるみたいです

@usasho
Copy link
Author

usasho commented Aug 25, 2018

Although this time PIL error, because the cause was found out, I will report it here. Please do not make tensorboardX version 1.2 or later.

@creatorrr
Copy link

Nice catch, @usasho .

Similar error reported for tensorboardX==1.4 in other packages, for example:
inferno-pytorch/inferno#142 (comment)

@Martin-Laclaustra
Copy link

Solved in tensorboardX v1.6.
It is not necessary to constrain the version any more.

@tripzero
Copy link
Contributor

tripzero commented Jun 25, 2019

I'm seeing this in tensorboardX 1.7:

python3 train.py --data-root=./out/ --preset=presets/deepvoice3_vctk.json 
Command line args:
 {'--checkpoint': None,
 '--checkpoint-dir': 'checkpoints',
 '--checkpoint-postnet': None,
 '--checkpoint-seq2seq': None,
 '--data-root': './out/',
 '--help': False,
 '--hparams': '',
 '--load-embedding': None,
 '--log-event-path': None,
 '--preset': 'presets/deepvoice3_vctk.json',
 '--reset-optimizer': False,
 '--restore-parts': None,
 '--speaker-id': None,
 '--train-postnet-only': False,
 '--train-seq2seq-only': False}
Training whole model
Training seq2seq model
Hyperparameters:
  adam_beta1: 0.5
  adam_beta2: 0.9
  adam_eps: 1e-06
  allow_clipping_in_normalization: True
  amsgrad: False
  batch_size: 16
  binary_divergence_weight: 0.1
  builder: deepvoice3_multispeaker
  checkpoint_interval: 10000
  clip_thresh: 0.1
  converter_channels: 256
  decoder_channels: 256
  downsample_step: 4
  dropout: 0.050000000000000044
  embedding_weight_std: 0.1
  encoder_channels: 512
  eval_interval: 10000
  fft_size: 1024
  fmax: 7600
  fmin: 125
  force_monotonic_attention: True
  freeze_embedding: False
  frontend: en
  guided_attention_sigma: 0.4
  hop_size: 256
  ignore_recognition_level: 2
  initial_learning_rate: 0.0005
  kernel_size: 3
  key_position_rate: 7.6
  key_projection: True
  lr_schedule: noam_learning_rate_decay
  lr_schedule_kwargs: {}
  masked_loss_weight: 0.5
  max_positions: 1024
  min_level_db: -100
  min_text: 20
  n_speakers: 108
  name: deepvoice3
  nepochs: 2000
  num_mels: 80
  num_workers: 2
  outputs_per_step: 1
  padding_idx: 0
  pin_memory: True
  power: 1.4
  preemphasis: 0.97
  priority_freq: 3000
  priority_freq_weight: 0.0
  process_only_htk_aligned: False
  query_position_rate: 2.0
  ref_level_db: 20
  replace_pronunciation_prob: 0.5
  rescaling: False
  rescaling_max: 0.999
  sample_rate: 22050
  save_optimizer_state: True
  speaker_embed_dim: 16
  speaker_embedding_weight_std: 0.05
  text_embed_dim: 256
  trainable_positional_encodings: False
  use_decoder_state_for_postnet_input: True
  use_guided_attention: True
  use_memory_mask: True
  value_projection: True
  weight_decay: 0.0
  window_ahead: 3
  window_backward: 1
Log event path: log/run-test2019-06-24_17:16:26.783904
2755it [57:20,  2.48s/it]
Loss: 0.5053848431136344
2755it [57:40,  2.60s/it]
Loss: 0.4032350966264029
2755it [57:53,  2.69s/it]
Loss: 0.37271299628294097
1735it [36:28,  1.21s/it]Save intermediate states at step 10000
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2428, in fromarray
    mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 35), '|u1')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train.py", line 981, in <module>
    train_seq2seq=train_seq2seq, train_postnet=train_postnet)
  File "train.py", line 709, in train
    mel, y, input_lengths, checkpoint_dir)
  File "train.py", line 445, in save_states
    writer.add_image(tag, np.uint8(cm.viridis(np.flip(alignment, 1).T) * 255), global_step)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/writer.py", line 533, in add_image
    image(tag, img_tensor, dataformats=dataformats), global_step, walltime)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/summary.py", line 224, in image
    image = make_image(tensor, rescale=rescale)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/summary.py", line 262, in make_image
    image = Image.fromarray(tensor)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2431, in fromarray
    raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type```

@tripzero
Copy link
Contributor

Anyone else seeing this? Should this be reopened?

@01ghost13
Copy link

01ghost13 commented Jul 22, 2019

Was caught in google colab environment.
tensorboardX 1.8:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2416, in fromarray
    mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 75), '|u1')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train.py", line 981, in <module>
    train_seq2seq=train_seq2seq, train_postnet=train_postnet)
  File "train.py", line 715, in train
    eval_model(global_step, writer, device, model, checkpoint_dir, ismultispeaker)
  File "train.py", line 412, in eval_model
    writer.add_image(tag, np.uint8(cm.viridis(np.flip(alignment, 1).T) * 255), global_step)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/writer.py", line 548, in add_image
    image(tag, img_tensor, dataformats=dataformats), global_step, walltime)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/summary.py", line 216, in image
    image = make_image(tensor, rescale=rescale)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/summary.py", line 256, in make_image
    image = Image.fromarray(tensor)
  File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2419, in fromarray
    raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type
Exception ignored in: <bound method tqdm.__del__ of 46it [00:15,  3.69it/s]>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/tqdm/_tqdm.py", line 931, in __del__
    self.close()
  File "/usr/local/lib/python3.6/dist-packages/tqdm/_tqdm.py", line 1133, in close
    self._decr_instances(self)
  File "/usr/local/lib/python3.6/dist-packages/tqdm/_tqdm.py", line 496, in _decr_instances
    cls.monitor.exit()
  File "/usr/local/lib/python3.6/dist-packages/tqdm/_monitor.py", line 52, in exit
    self.join()
  File "/usr/lib/python3.6/threading.py", line 1053, in join
    raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread

@harirawat
Copy link

Getting same error in google colab.
tensorboardX 1.8

Command line args:
 {'--checkpoint': None,
 '--checkpoint-dir': 'checkpoints',
 '--checkpoint-postnet': None,
 '--checkpoint-seq2seq': None,
 '--data-root': './datasets/processeddata',
 '--help': False,
 '--hparams': 'builder=deepvoice3,num_workers=1,n_speakers=1,batch_size=6,checkpoint_interval=100',
 '--load-embedding': None,
 '--log-event-path': None,
 '--preset': 'presets/deepvoice3_vctk.json',
 '--reset-optimizer': False,
 '--restore-parts': '20171222_deepvoice3_vctk108_checkpoint_step000300000.pth',
 '--speaker-id': None,
 '--train-postnet-only': False,
 '--train-seq2seq-only': False}
Training whole model
Training seq2seq model
Hyperparameters:
  adam_beta1: 0.5
  adam_beta2: 0.9
  adam_eps: 1e-06
  allow_clipping_in_normalization: True
  amsgrad: False
  batch_size: 6
  binary_divergence_weight: 0.1
  builder: deepvoice3
  checkpoint_interval: 100
  clip_thresh: 0.1
  converter_channels: 256
  decoder_channels: 256
  downsample_step: 4
  dropout: 0.050000000000000044
  embedding_weight_std: 0.1
  encoder_channels: 512
  eval_interval: 10000
  fft_size: 1024
  fmax: 7600
  fmin: 125
  force_monotonic_attention: True
  freeze_embedding: False
  frontend: en
  guided_attention_sigma: 0.4
  hop_size: 256
  ignore_recognition_level: 2
  initial_learning_rate: 0.0005
  kernel_size: 3
  key_position_rate: 7.6
  key_projection: True
  lr_schedule: noam_learning_rate_decay
  lr_schedule_kwargs: {}
  masked_loss_weight: 0.5
  max_positions: 1024
  min_level_db: -100
  min_text: 20
  n_speakers: 1
  name: deepvoice3
  nepochs: 2000
  num_mels: 80
  num_workers: 1
  outputs_per_step: 1
  padding_idx: 0
  pin_memory: True
  power: 1.4
  preemphasis: 0.97
  preset: deepvoice3_vctk.json
  priority_freq: 3000
  priority_freq_weight: 0.0
  process_only_htk_aligned: False
  query_position_rate: 2.0
  ref_level_db: 20
  replace_pronunciation_prob: 0.5
  rescaling: False
  rescaling_max: 0.999
  sample_rate: 22050
  save_optimizer_state: True
  speaker_embed_dim: 16
  speaker_embedding_weight_std: 0.05
  text_embed_dim: 256
  trainable_positional_encodings: False
  use_decoder_state_for_postnet_input: True
  use_guided_attention: True
  use_memory_mask: True
  value_projection: True
  weight_decay: 0.0
  window_ahead: 3
  window_backward: 1
Restore part of the model from: 20171222_deepvoice3_vctk108_checkpoint_step000300000.pth
Log event path: log/run-test2019-07-22_11:16:19.248580
0it [00:00, ?it/s]THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=663 error=11 : invalid argument
25it [00:02,  9.96it/s]
Loss: 18.01471851348877
25it [00:02,  9.80it/s]
Loss: 7.743541326522827
25it [00:02, 10.32it/s]
Loss: 3.732187213897705
25it [00:02, 10.08it/s]
Loss: 2.7462184238433838
0it [00:00, ?it/s]Save intermediate states at step 100

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2416, in fromarray
    mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 145), '|u1')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train.py", line 981, in <module>
    train_seq2seq=train_seq2seq, train_postnet=train_postnet)
  File "train.py", line 709, in train
    mel, y, input_lengths, checkpoint_dir)
  File "train.py", line 445, in save_states
    writer.add_image(tag, np.uint8(cm.viridis(np.flip(alignment, 1).T) * 255), global_step)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/writer.py", line 548, in add_image
    image(tag, img_tensor, dataformats=dataformats), global_step, walltime)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/summary.py", line 216, in image
    image = make_image(tensor, rescale=rescale)
  File "/usr/local/lib/python3.6/dist-packages/tensorboardX/summary.py", line 256, in make_image
    image = Image.fromarray(tensor)
  File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2419, in fromarray
    raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type

@abenbihi
Copy link

abenbihi commented Aug 2, 2019

I was having the same issue when feeding the image in HxWxC format. I switched to CxHxW and it solved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants