Home > Enterprise >  Keras: I don't know how to create a Inception_v3 model
Keras: I don't know how to create a Inception_v3 model

Time:08-03

I want to create a inception v3 model:

model = InceptionV3(weights='imagenet')

It downloads put when I got following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/5q/hv9z8c6d0633l17lp_1k6sz80000gn/T/ipykernel_891/1727938959.py in <module>
      1 #model = InceptionV3(weights='imagenet')
      2 #model.summary
----> 3 model = InceptionV3(weights='imagenet')
      4 model.summary

/opt/anaconda3/envs/nn_env/lib/python3.7/site-packages/tensorflow_core/python/keras/applications/__init__.py in wrapper(*args, **kwargs)
     47     kwargs['models'] = models
     48     kwargs['utils'] = utils
---> 49     return base_fun(*args, **kwargs)
     50   return wrapper
     51 

/opt/anaconda3/envs/nn_env/lib/python3.7/site-packages/tensorflow_core/python/keras/applications/inception_v3.py in InceptionV3(*args, **kwargs)
     30 @keras_modules_injection
     31 def InceptionV3(*args, **kwargs):
---> 32   return inception_v3.InceptionV3(*args, **kwargs)
     33 
     34 

/opt/anaconda3/envs/nn_env/lib/python3.7/site-packages/keras_applications/inception_v3.py in InceptionV3(include_top, weights, input_tensor, input_shape, pooling, classes, **kwargs)
    389                 cache_subdir='models',
    390                 file_hash='bcbd6486424b2319ff4ef7d526e38f63')
--> 391         model.load_weights(weights_path)
    392     elif weights is not None:
    393         model.load_weights(weights)

/opt/anaconda3/envs/nn_env/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py in load_weights(self, filepath, by_name)
    179         raise ValueError('Load weights is not yet supported with TPUStrategy '
    180                          'with steps_per_run greater than 1.')
--> 181     return super(Model, self).load_weights(filepath, by_name)
    182 
    183   @trackable.no_automatic_dependency_tracking

/opt/anaconda3/envs/nn_env/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py in load_weights(self, filepath, by_name)
   1175         saving.load_weights_from_hdf5_group_by_name(f, self.layers)
   1176       else:
-> 1177         saving.load_weights_from_hdf5_group(f, self.layers)
   1178 
   1179   def _updated_config(self):

/opt/anaconda3/envs/nn_env/lib/python3.7/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' 

Can some one help me? I don't what the cause of the error is.

CodePudding user response:

Stuff like this is usually a mismatched TF and Keras pip version. Make sure you are importing tf.keras, not keras. And run pip show tensorflow and pip show keras. If they aren't the same version, you'll have to upgrade them to the same version via something like this

pip install -U pip
pip uninstall keras
pip install -U tensorflow

CodePudding user response:

Here is a recommended fix: https://stackoverflow.com/a/64635871/19543236

For me the solution was downgrading the h5py package (in my case to 2.10.0), apparently putting back only Keras and Tensorflow to the correct versions was not enough.

And the action to do: https://stackoverflow.com/a/65717773/19543236

pip install 'h5py==2.10.0' --force-reinstall

As a side note, I recommend you update your version of Tensorflow: https://github.com/tensorflow/tensorflow/releases/latest

  • Related