I am trying to develop a simple image classification model in Azure ML notebooks. ResNet50 model was trained and the custom weights from the model is being used in the following code for image classification. The custom weights are saved in a folder called Model.
import os
working_directory = os.getcwd()
model_directory = working_directory + "/Model/model.h5"
The above code is being used for accessing the saved model.
def classifyingImages(image_list):
value = 0
for image in image_list:
image_resized = cv2.resize(image, (img_height, img_width))
image = np.expand_dims(image_resized, axis=0)
model = load_model(model_directory)
#classifying the image
prediction = model.predict(image)
output_class = class_names[np.argmax(prediction)]
#getting the image name
image_name = img_name_list[value]
print(image_name)
if(np.argmax(prediction)==0):
print("check negative")
# cv2.imwrite((negative_path+"/"+image_name), image)
else:
print("check positive")
# cv2.imwrite((path_positive+"/"+image_name), image)
value = value +1
return value
classifyingImages(image_list)
The code added above is the image classification code
The image_list
contains the test images which saved in the blob storage.
After running the classification function i get the error str' object has no attribute 'decode
and as a solution i tried to change the h5py lib version using below code. But still it gives me the same error. It would be great if i could a solution for this issue. Thank you in advance.
!pip install h5py==2.10.0
The stack trace
AttributeError Traceback (most recent call last)
<ipython-input-96-6e38a2f74291> in <module>
42 return value
43
---> 44 classifyingImages(image_list)
<ipython-input-96-6e38a2f74291> in classifyingImages(image_list)
20 print(image.dtype)
21
---> 22 model = load_model(model_directory)
23
24 #classifying the image
/anaconda/envs/azureml_py36/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/save.py in load_model(filepath, custom_objects, compile)
144 if (h5py is not None and (
145 isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
--> 146 return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
147
148 if isinstance(filepath, six.string_types):
/anaconda/envs/azureml_py36/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py in load_model_from_hdf5(filepath, custom_objects, compile)
164 if model_config is None:
165 raise ValueError('No model found in config file.')
--> 166 model_config = json.loads(model_config.decode('utf-8'))
167 model = model_config_lib.model_from_config(model_config,
168 custom_objects=custom_objects)
AttributeError: 'str' object has no attribute 'decode'