Import "tensorflow.keras.preprocessing.image" could not be resolved(reportMissingImports)


In the Course-2 Week 2 Assignment, I am getting the below error in Colab:

Import "tensorflow.keras.preprocessing.image" could not be resolved(reportMissingImports)

I have tried
pip install --upgrade keras-applications keras-preprocessing
but it didn’t solve the problem.

Then I also followed this solution but it didn’t work as well.

Colab failing with Keras and tensorFLow backend · Issue #408 · googlecolab/colabtools · GitHub

Hello maruf,

Did this error showed after import section?

Can you post a screenshot of that error here?

Inside train_val_generatorsfunction the ImageDataGenerator function is being called. But as the tensorflow.keras.preprocessing.image could not be resolved so train_val_generators returning none

Hi maruf,

I just ran the same cell and it run successfully. Is the Colab connected with your google drive?

Did you run the cell before the import cell?

Did you have a look at this document
You will also need to create the helper functions to move the images around the filesystem as you did last week, so if you need to refresh your memory with the os module be sure to take a look a the docs.

No, I’ve tried

Run All

Restart Kernel and Run All

I’ve also did complete the helper functions that I’ve created last week. And all that cells shows correct output. But getting error only here

For the import cell when you got this import failure,

did you find any stackoverflow link below like how you got for the grader cell.

Try this once.

Shut down the kernel. Close the page. clear your cache history and restart your system and try again from first cell.

I’ve found a github issue that I’ve mentioned in the post. And did as it said. But it didn’t solve my problem.

I know they tell you to use pip install option. no but it is clearly mentioned not to add any extra grader cell. Probably there might be issue with your metadata or test files. make sure to refresh your browser and try again. I am here. Let me know if you still encountering the same issue.


were you able to run the below cell successfully

from google.colab import drive

When you run the above cell, it ask you permission to connect with your google drive. I hope you followed the same.

This cell was not given in the assignment. I didn’t write that cell.
The assignment notebooks was in github and I clicked Save a Copy in Drive as it was mentioned in the previous assignment. I even created another copy of the assignment but still it is giving the same error

For me the assignment book looks like this, does it match with yours’

Nope. Mine look like this.

Can you please check the assignment notebook link: Google Colab


Can you change “tensorflow.keras.preprocessing.image” to “keras_preprocessing.image” and see if it runs successfully in the import section.

This worked perfectly fine in my system

Well, actually there was an error in my code. I just found out now.
Validation datagen was set to none. And I never actually set validation_datagen but was calling validation_datagen.flow_from_directory

validation_datagen = None

Thanks for trying to help me out. And I’m really sorry for doing this silly mistake and wasting your precious time.

Please remove that grader cell codes. It is against community guidelines.

So it is working fine now?

then why was your import showing that error?

So far what I’ve read in the stackoverflow and github issues, I’ve found out that this API is deprecated. This is why colab shows this warning. But the code works fine.