C3_W3_Assignment: UNQ_C2 error!

Hi

I get following error , when I run UNQ_C2 cell. Please help.

“”"
Ground Truth: Cardiomegaly

ValueError Traceback (most recent call last)
in ()
3 image_filename = ‘00016650_000.png’
4 labels_to_show = [‘Cardiomegaly’, ‘Mass’, ‘Edema’]
----> 5 compute_gradcam(model, image_filename, mean, std, IMAGE_DIR, df, labels, labels_to_show)

in compute_gradcam(model, img, mean, std, data_dir, df, labels, selected_labels, layer_name)
39
40 # Use the grad_cam function to calculate gradcam
—> 41 gradcam = grad_cam(model, img, i, layer_name=layer_name) #None
42
43 ### END CODE HERE ###

in grad_cam(input_model, image, category_index, layer_name)
42
43 # Put in the image to calculate the values of the spatial_maps (selected layer) and values of the gradients
—> 44 spatial_map_all_dims, grads_val_all_dims = spatial_map_and_gradient_function([image]) #None
45
46 # Reshape activations and gradient to remove the batch dimension

/opt/conda/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in call(self, inputs)
2480 session = get_session()
2481 updated = session.run(fetches=fetches, feed_dict=feed_dict,
→ 2482 **self.session_kwargs)
2483 return updated[:len(self.outputs)]
2484

/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
893 try:
894 result = self._run(None, fetches, feed_dict, options_ptr,
→ 895 run_metadata_ptr)
896 if run_metadata:
897 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1095 feed_handles[subfeed_t] = subfeed_val
1096 else:
→ 1097 np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
1098
1099 if (not is_tensor_handle_feed and

/opt/conda/lib/python3.6/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
83
84 “”"
—> 85 return array(a, dtype, copy=False, order=order)
86
87

ValueError: could not convert string to float: ‘00016650_000.png’

“”"

Hi @Bonny_Patel,

The error message says that it is impossible to convert string into float.
The ‘00016650_000.png’ of the problem part is an image name.
I suppose it might be helpful to check the argument “img” of the function “compute_gradcam()”.

Best regards,

Nakamura

thanks @nakamura for response.

“img” argument seems to be fine. Here is my call inside the " compute_grad_cam() " function, from where the error seems to be coming from (below line).

gradcam = grad_cam(model, img, i, layer_name=layer_name) . Here " i " is the index for the label in “selected_labels” input parameter.

if you look at the code in next cell that calls the function, “img” argument seems fine.

df = pd.read_csv("data/nih_new/train-small.csv")

image_filename = '00016650_000.png'
labels_to_show = ['Cardiomegaly', 'Mass', 'Edema']
compute_gradcam(model, image_filename, mean, std, IMAGE_DIR, df, labels, labels_to_show)

I think, I have solved it . it’s using preprocessed_input parameter in internal grad_cam function call. My assignment pass the auto-grader.