DeepRNN / image_captioning

Tensorflow implementation of "Show, Attend and Tell: Neural Image Caption Generation with Visual Attention"
MIT License
781 stars 351 forks source link

'NoneType' object has no attribute 'swapaxes' #31

Open pranjalnaman opened 6 years ago

pranjalnaman commented 6 years ago

How do I get around this error: Traceback (most recent call last): File "main.py", line 69, in tf.app.run() File "C:\Python36\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run _sys.exit(main(argv)) File "main.py", line 50, in main model.train(sess, data) File "C:\Users\pranj\Desktop\img_cap\base_model.py", line 50, in train images = self.image_loader.load_images(image_files) File "C:\Users\pranj\Desktop\img_cap\utils\misc.py", line 35, in load_images images.append(self.load_image(image_file)) File "C:\Users\pranj\Desktop\img_cap\utils\misc.py", line 19, in load_image temp = image.swapaxes(0, 2) AttributeError: 'NoneType' object has no attribute 'swapaxes'

NoohAzhar commented 6 years ago

I had the same error! The problem was that the train/val images weren't in the same directory that was specified in the config file. So, please check that.

lfydegithub commented 6 years ago

@NoohAzhar pls, be detailed...I cannot understand

NoohAzhar commented 6 years ago

@lfydegithub Several reasons could cause this error. In my case i faced it 2 times with this source code, and both times were the reason is that the images object weren't created correctly!!

  1. In the first case was during training phase and it was because of wrong path problem. I added the images to subfolder inside the folder declared in the config. so, the code while creating the images object created them without actual image source!! So i solved it by fixing the images folder path.
  2. The second case was during testing phase. when I debugged it i noticed that there are names of images that actually not exist in the testing images folder!! to be honest i don't know why or where they came from i just replaced the folder with newly created one and moved the testing images to it and it worked!!
lfydegithub commented 6 years ago

@NoohAzhar sry,my fault. there has chinese characters in test img name...LOL

liujiangtaoyd commented 6 years ago

thanks @NoohAzhar

AnwarUllahKhan commented 5 years ago

@NoohAzhar I am facing the same problem please give me some details about thar how can I solve that?

CNN built. Building the RNN... RNN built. Training the model... epoch: 0%| | 0/100 [00:00<?, ?it/s] batch: 0%| | 0/11290 [00:00<?, ?it/s]

Traceback (most recent call last):

File "", line 80, in tf.app.run()

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run _sys.exit(main(argv))

File "", line 60, in main model.train(sess, data)

File "H:\First Neural Network\image_captioning-master\base_model.py", line 46, in train images = self.image_loader.load_images('./train/images')

File "H:\First Neural Network\image_captioning-master\utils\misc.py", line 34, in load_images images.append(self.load_image(image_file))

File "H:\First Neural Network\image_captioning-master\utils\misc.py", line 18, in load_image temp = image.swapaxes(0, 2)

AttributeError: 'NoneType' object has no attribute 'swapaxes'

NoohAzhar commented 5 years ago

@AnwarUllahKhan I would recommend you to check the following:

  1. Images in correct path
  2. Images name doesn’t have Chinese, korean, Arabic ... etc characters
  3. The images format ( jpg, jpeg)
  4. Images folder is clean from other type of files
AnwarUllahKhan commented 5 years ago

@NoohAzhar

  1. My images are in the correct path which is mention on the config file. self.train_image_dir = './train/images/'
  2. Images name is same as coco dataset like COCO_train2014_000000581712.jpg etc
  3. all images in jpg format.
  4. The images folder have built-in one file "readme" can I delete that one?

highly recommended your reply....

NoohAzhar commented 5 years ago

@AnwarUllahKhan I’m not really sure but yes try to delete that readme file . If it didn’t work maybe some debugging could be helpful

AnwarUllahKhan commented 5 years ago

@NoohAzhar dear, If you have this code then share it with me, thank you very much. my email id is anwarullah0343@gmail.com

NoohAzhar commented 5 years ago

@AnwarUllahKhan I didn’t made any changes on the code, Just downloaded from here!!!

AnwarUllahKhan commented 5 years ago

@NoohAzhar just show me your path how you assign the path? I am still facing the problem, I am trying from too many days....

AnwarUllahKhan commented 5 years ago

@NoohAzhar how much time it's taking to train? Please tell me as soon as possible. How much time does it take when you train it?

kangkang59812 commented 5 years ago

@AnwarUllahKhan did you solve the problem?i am confused too.

Kinghup commented 5 years ago

@NoohAzhar how much time it's taking to train? Please tell me as soon as possible. How much time does it take when you train it?

how do you solve the problem? I have the same problem like you and I check the path many times. I don't know where is wrong, please help me.

Kinghup commented 5 years ago

I solve the problem. If someone meet the same problem, you just need to check your image_path. And it's sure that the images folder directly include images. Modifying the path of config is useless.

56518 commented 5 years ago

I solve this problem by redoing ‘Put the COCO train2014 images in the folder train/images’ this move again.Because you may didn't copy it completely.Just wait for copying completed.

mymuli commented 5 years ago

路径问题

phyukhaing7 commented 5 years ago

I also face with this problem. If anybody has a solution, let me know. I check the image path but not okay. May I know the solution.

skywangch commented 5 years ago

I also face with this problem. If anybody has a solution, let me know. I check the image path but not okay. May I know the solution.

maybe you should delete the cache files in ./train ./test ./val

lenhhoxung86 commented 5 years ago

I have the same problem. In my case, I unzip the train and val images into the sub folder train2014 and test2014. Though I modified the file config.py, I got the same error as mentioned above. Only when I copy all the train images into train/images/ and all the val images into val/images/, it works.

ayulockin commented 4 years ago

Move the images from ./train/images/train2014 to ./train/images Like wise do for validation images, ie. from ./val/images/val2014 to ./val/images

If you are on linux based system. cd ./train/images/train2014 The do this: !find . -maxdepth 1 -exec mv {} .. \;

Do the same for val.

Reference: https://superuser.com/questions/88202/how-do-i-move-files-and-directories-to-the-parent-folder-in-linux