Week 1 model error in my notebook

util.compute_gradcam(model, ‘00008270_015.png’, IMAGE_DIR, df, labels, labels_to_show)
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9916\69387146.py in
----> 1 util.compute_gradcam(model, ‘00008270_015.png’, IMAGE_DIR, df, labels, labels_to_show)

~\Documents\4-Coursera codes\1-AI for Medical Diagnosis\2- week 1 submission\work\W1A1\util.py in compute_gradcam(model, img, image_dir, df, labels, selected_labels, layer_name)
62 sample_data.append(x)
63
—> 64 sample_data = np.concatenate(sample_data, axis=0)
65 mean = np.mean(sample_data, axis=(0, 1, 2, 3))
66 std = np.std(sample_data, axis=(0, 1, 2, 3))

~\Documents\4-Coursera codes\1-AI for Medical Diagnosis\2- week 1 submission\work\W1A1\util.py in load_image(img, image_dir, df, preprocess, H, W)
29 sample_data =
30 for img in df.sample(100)[“Image”].values:
—> 31 image_path = os.path.join(image_dir, img)
32 sample_data.append(
33 np.array(image.load_img(image_path, target_size=(H, W))))

~\Documents\4-Coursera codes\1-AI for Medical Diagnosis\2- week 1 submission\work\W1A1\util.py in get_mean_std_per_batch(image_dir, df, H, W)
20 from tensorflow.keras.models import Model
21 from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
—> 22
23 random.seed(a=None, version=2)
24

AttributeError: module ‘keras.preprocessing.image’ has no attribute ‘load_img’

can you help me please?

I’m not a mentor for AI4M, but looking at your exception trace it’s clear you are running the notebook locally on your own computer. That can cause “versionitis” problems, because the notebooks in the courses here were designed to work with whatever versions of the TF/Keras APIs and other packages that were current at the time the assignment was initially published. Unfortunately things evolve pretty rapidly in this space, so you can’t guarantee that the notebooks will work with whatever the more recent versions are that you have installed on your system.

There are ways to duplicate version environments using tools like Anaconda, but this is not a simple matter and we do not have any official documentation about how to do it. Here’s a thread which will get you started down that road.

The other alternative is that you just have to debug each such problem as you encounter it.

Of course the simplest alternative is just to work only on the Coursera website with the course assignments. Also note that it’s not a safe thing to work on the notebooks in a different environment and then upload them back to the Coursera site. Some external tools modify the JSON “metadata” in the notebooks in ways that may not be compatible with the Coursera graders. In particular, we have seen concrete cases in which Google Colab rewrites our notebooks in incompatible ways, although of course that’s not the case you have here. Just a warning in general.

Thank you for your interest.I wish they would have added information or training on how we use grad-cam. I could not understand how we diagnose diseases with grad-cam

Sorry, as I mentioned in my earlier reply, I am not a mentor for AI4M and have not even taken the course, so I’m not able to contribute anything on the grad-cam question. But if you want that to be noticed by someone who can help, it would be a good idea to create a new thread with that in the title and put it in the appropriate category. Tacking this question onto this thread with an unrelated title makes it less likely to be noticed …

Just googling “grad-cam” gets some interesting hits, e.g. this paper.

And this medium article and several more on StackExchange.

thank you sir! you have helped me a lot