1
import numpy as np
import cv2
from tensorflow.keras.models import load_model
model = load_model("my_model_new.h5")

while True:
    success, imgOriginal = cap.read()
    img = np.asarray(imgOriginal)
    img = cv2.resize(img, (32, 32))
    img = preprocessing(img)
    cv2.imshow("Processed Image", img)
    img = img.reshape(1, 32, 32, 1)

    predictions = model.predict(img)
    classIndex = np.argmax(predictions)

    predictions = model.predict(img)
    probVal= np.amax(predictions)
    if probVal > threshold:
        cv2.putText(imgOriginal, str(getClassName(classIndex))+" "+ str(probVal),(50,50),font,1,(0,0,255),1,cv2.LINE_AA)
        cv2.imshow("Original Image", imgOriginal)

    if cv2.waitKey(1) and 0xFF == ord('q'):
        break

This is a traffic sign recognition testing part partial code. When i run the code im getting this attribute error message and i dont know how to fix this. So omeone please tell me a fix for this error.

saurabheights
  • 3,967
  • 2
  • 31
  • 50
auxiler
  • 11
  • 2
  • Can you post the error message as well. – saurabheights Apr 16 '23 at 08:58
  • model_config = json.loads(model_config.decode('utf-8')) AttributeError: 'str' object has no attribute 'decode' – auxiler Apr 16 '23 at 09:57
  • You dont need to call decode when you already have str object. Just use `json.loads(model_config)`. Furthermore where exactly is this error coming in above code you provided? – saurabheights Apr 16 '23 at 10:18
  • but in the code where exactly i need to change. i think the error is at the bottom lines 3 and 4 – auxiler Apr 16 '23 at 10:25
  • Hi, please go through https://stackoverflow.com/questions/4929251/how-to-step-through-python-code-to-help-debug-issues and https://github.com/tensorflow/tensorflow/blob/1f81aa0cf0839c496014e65c8ac427edbc41feb8/tensorflow/python/keras/saving/hdf5_format.py#L177 You dont need to guess the line number – saurabheights Apr 16 '23 at 10:43
  • I believe this might be an issue in tensorflow, which is probably already fixed since latest code first checks if decode attribute is available before calling decode. See - https://github.com/tensorflow/tensorflow/blob/1f81aa0cf0839c496014e65c8ac427edbc41feb8/tensorflow/python/keras/saving/hdf5_format.py#L177 – saurabheights Apr 16 '23 at 10:43

1 Answers1

2

The issue is due to a bug in Tensorflow and h5py compatibility. See tensorflow github issue.

You can either install tensorflow with h5py version less than 3.0.0 (See comment, doesnt work always though - see comment)

pip install tensorflow h5py<3.0.0

or upgrade tensorflow to version higher than 2.4.0.

saurabheights
  • 3,967
  • 2
  • 31
  • 50