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

ValueError: NumpyArrayIterator is set to use the data format convention "channels_last" #3

Closed
HellFireC02 opened this issue Dec 3, 2019 · 4 comments

Comments

@HellFireC02
Copy link

HellFireC02 commented Dec 3, 2019

Excuse me, i have a question that cant solve for a long time.

I want to use your code to deal with clustering task by using NUS-WIDE dataset.
I organize these images on your suggestion in 'data' folder and put nus_lable.txt in 'meta' folder.
Then i add 'resize' operation in your 'mc_dataset.py'
It's just about:
1.from skimage.transform import resize
2.img = resize(img, (32, 32)) ------before 30 line

Besides, I just modified cifar10.yaml for:
small_bs: 16
workers: 4
num_classes: 4

Other than the above, I didn't modify any other files.(Except some notes I wrote)

But when i run 'main_2.py' using 'python main_2.py --config cfgs/cifar10.yaml'
(main_2.py is just a copy of main.py and added with my note)
It shows:

Traceback (most recent call last):
File "main_2.py", line 309, in
main()
File "main_2.py", line 140, in main
train(dataloader, model, dim_loss, crit_label, crit_graph, crit_c, optimizer, epoch, datagen, tb_logger)
File "main_2.py", line 203, in train
for X_batch_i in datagen.flow(input_bs,batch_size=args.small_bs,shuffle=False):
File "/home/sky/anaconda2/lib/python2.7/site-packages/keras/preprocessing/image.py", line 460, in flow
save_format=save_format)
File "/home/sky/anaconda2/lib/python2.7/site-packages/keras/preprocessing/image.py", line 782, in init
' (' + str(self.x.shape[channels_axis]) + ' channels).')
ValueError: NumpyArrayIterator is set to use the data format convention "channels_last" (channels on axis 3), i.e. expected either 1, 3 or 4 channels on axis 3. However, it was passed an array with shape (16, 3, 32, 32) (32 channels).

I dont know how to solve this problem.
Is something wrong for my modification?
Or your main.py has something need to revise?
I would appreciate it if you could help me solve this problem!

@Cory-M
Copy link
Owner

Cory-M commented Dec 7, 2019

Hi, sorry for the late reply. You could change the "image_data_format" from channels_last to channels_first in you Keras configuration file. (usually, it's at $HOME/.keras/keras.json) I think that would help to solve the issue.
Let me know if bugs still exist.

@HellFireC02
Copy link
Author

Hi, sorry for the late reply. You could change the "image_data_format" from channels_last to channels_first in you Keras configuration file. (usually, it's at $HOME/.keras/keras.json) I think that would help to solve the issue.
Let me know if bugs still exist.

thanks for your reply, but this leads to another error...
it shows:

Traceback (most recent call last):
File "main_2.py", line 309, in
main()
File "main_2.py", line 140, in main
train(dataloader, model, dim_loss, crit_label, crit_graph, crit_c, optimizer, epoch, datagen, tb_logger)
File "main_2.py", line 188, in train
input_bs = input_tensor[address]
RuntimeError: index 921 is out of bounds for dim with size 855

I think the reason for this error is the setting of 'address', or the 'large_bs' and the 'small_bs'.
specifically,i set:

large_bs: 1000
small_bs: 16
repeated: 10
input_size: 32
workers: 4
num_classes: 4

so i wonder that something wrong in my above setting.
should i change large_bs or num_classes?
looking forward to your reply!

@Cory-M
Copy link
Owner

Cory-M commented Dec 10, 2019

you could simply add "drop_last=True" in torch.utils.data.DataLoader at line 92 in the original main.py : ) also refer to the other closed issue at #2 is necessary.

@HellFireC02
Copy link
Author

thanks for your kindly help
there's no any error during running period!

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

2 participants