Course 4, Week 3, Assignment 1: No module named 'keras'

Hi,

I’m trying to import keras but I keep getting the ModuleNotFoundError: No module named ‘keras’. Here’s the error message. Could anyone take a look at this issue?

Thank you


ModuleNotFoundError Traceback (most recent call last)
in
10 from PIL import ImageFont, ImageDraw, Image
11 import tensorflow as tf
—> 12 from keras import backend as K
13 from tensorflow.python.framework.ops import EagerTensor
14 from tensorflow.keras.models import load_model

ModuleNotFoundError: No module named ‘keras’

C4 Week 3 Assignment 1 is YOLO. I do not see any statement like that in the YOLO notebook. Have you modified the import cell of the notebook?

Are you running the notebook on the Coursera website or have you downloaded it and are trying to run it locally? If the latter, then you need to install quite a lot of software in your local environment.

1 Like

Ah, ok, I think I figured out what is going on: you are using the OLD version of the YOLO assignment from the previous version of the course. That will not work here: one of the major points of the new version of the courses is that everything has been updated from TensorFlow 1.0 to TensorFlow 2.0. There were quite a few changes in addition to just that in the particular case of the YOLO assignment: they also changed the definitions of some of the local APIs that are specific to this notebook.

You can’t just import your old notebook: you have to start with the new one. You can try “copy/pasting” over some of your work, but you need to be very careful to read the new notebook and pay attention to all the details.

1 Like

Hi Paulinpaloalto,

Thank you very much for your reply. I’m taking the Deeplearning Specialization on Coursera. This is the only version that I can access to. Could you please tell me where to find the new version notebook so I can finish the assignment?

Thank you

1 Like

Hmmm, when did you first sign up for the DLS specialization? The first step would be to try the “Get a Fresh Copy” procedure which is documented on the FAQ Thread.

If that doesn’t get you the new version, then my guess is that your account is somehow misconfigured. The next thing to try is to contact the Coursera Help Center and ask them to un-enroll you and then re-enroll you in the course to make sure you are in the current version. There’s a topic also on the FAQ Thread about how to contact the Coursera Help Center.

Just for reference, here’s what the “Import” cell at the beginning of the notebook should look like if you have the new (current) version:

import argparse
import os
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
import scipy.io
import scipy.misc
import numpy as np
import pandas as pd
import PIL
from PIL import ImageFont, ImageDraw, Image
import tensorflow as tf
from tensorflow.python.framework.ops import EagerTensor

from tensorflow.keras.models import load_model
from yad2k.models.keras_yolo import yolo_head
from yad2k.utils.utils import draw_boxes, get_colors_for_classes, scale_boxes, read_classes, read_anchors, preprocess_image

%matplotlib inline

But this is about the fifth assignment in the course. Are you sure you didn’t have this kind of problem with any of the previous ones?

Hi Paulinpaloalto,

I tried to updated to the latest version, but it’s still not working. Here’s the original code of the packages imported by this assignment on my notebook, would you please take a look? Is it the latest version?

import argparse
import os
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
import scipy.io
import scipy.misc
import numpy as np
import pandas as pd
import PIL
from PIL import ImageFont, ImageDraw, Image
import tensorflow as tf
from tensorflow.python.framework.ops import EagerTensor

from tensorflow.keras.models import load_model
from yad2k.models.keras_yolo import yolo_head
from yad2k.utils.utils import draw_boxes, get_colors_for_classes, scale_boxes, read_classes, read_anchors, preprocess_image

%matplotlib inline

Hi Paulinpaloalto,

Thank you very much for your help. I didn’t have any problems with any previous assignment.

1 Like

The import code you show looks correct. Compare it to what I showed. So you should not have any problem now. Note that it does not import “keras” anyplace, which is the original error message you were getting.

So what is it that makes you believe that you have a problem now?

Hi Paulinpalolto,

I renamed it and updated to the latest version and it’s working now! Thank you very much for your help!

1 Like