ARNAVA SHRESTHA
ARNAVA SHRESTHA

Reputation: 11

error: 'str' object has no attribute 'decode'

i am working on a sign language detection model,while running my prediction script, i am getting this error:

AttributeError: 'str' object has no attribute 'decode'

the code:

import numpy as np
from tensorflow.keras.models import model_from_json
import operator
import cv2
import sys, os
# Loading the model
json_file = open("model-bw.json", "r")
model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(model_json)
# load weights into new model
loaded_model.load_weights("model-bw.h5")
print("Loaded model from disk")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-98e040889abd> in <module>
      5 loaded_model = model_from_json(model_json)
      6 # load weights into new model
----> 7 loaded_model.load_weights("model-bw.h5")
      8 print("Loaded model from disk")

C:\PYTHON\Lib\site-packages\tensorflow_core\python\keras\engine\training.py in load_weights(self, filepath, by_name, skip_mismatch)
    232         raise ValueError('Load weights is not yet supported with TPUStrategy '
    233                          'with steps_per_run greater than 1.')
--> 234     return super(Model, self).load_weights(filepath, by_name, skip_mismatch)
    235 
    236   @trackable.no_automatic_dependency_tracking

C:\PYTHON\Lib\site-packages\tensorflow_core\python\keras\engine\network.py in load_weights(self, filepath, by_name, skip_mismatch)
   1220             f, self.layers, skip_mismatch=skip_mismatch)
   1221       else:
-> 1222         hdf5_format.load_weights_from_hdf5_group(f, self.layers)
   1223 
   1224   def _updated_config(self):

C:\PYTHON\Lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py in load_weights_from_hdf5_group(f, layers)
    649   """
    650   if 'keras_version' in f.attrs:
--> 651     original_keras_version = f.attrs['keras_version'].decode('utf8')
    652   else:
    653     original_keras_version = '1'

AttributeError: 'str' object has no attribute 'decode'

Upvotes: 0

Views: 395

Answers (1)

buran
buran

Reputation: 14233

Upgrade tensorflow. This was a reported issue due to h5py==3.3.0 version and is already fixed in tensorflow 2.5.0.

Current source code

Upvotes: 1

Related Questions