0

I am trying the import MobilenetV2 in the Azure ML Studio notebook, but I am getting an error. Please note that I can import the model running the same command via Jupyter notebook on my local machine.

import tensorflow as tf
from tensorflow import keras

model = tf.keras.applications.MobileNetV2()

The error log is as below

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [23], in <cell line: 1>()
----> 1 model = tf.keras.applications.MobileNetV2()

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/tensorflow/python/keras/applications/mobilenet_v2.py:405, in MobileNetV2(input_shape, alpha, include_top, weights, input_tensor, pooling, classes, classifier_activation, **kwargs)
    402     weight_path = BASE_WEIGHT_PATH + model_name
    403     weights_path = data_utils.get_file(
    404         model_name, weight_path, cache_subdir='models')
--> 405   model.load_weights(weights_path)
    406 elif weights is not None:
    407   model.load_weights(weights)

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:250, in Model.load_weights(self, filepath, by_name, skip_mismatch)
    246   if (self._distribution_strategy.extended.steps_per_run > 1 and
    247       (not network._is_hdf5_filepath(filepath))):  # pylint: disable=protected-access
    248     raise ValueError('Load weights is not yet supported with TPUStrategy '
    249                      'with steps_per_run greater than 1.')
--> 250 return super(Model, self).load_weights(filepath, by_name, skip_mismatch)

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/tensorflow/python/keras/engine/network.py:1266, in Network.load_weights(self, filepath, by_name, skip_mismatch)
   1263   hdf5_format.load_weights_from_hdf5_group_by_name(
   1264       f, self.layers, skip_mismatch=skip_mismatch)
   1265 else:
-> 1266   hdf5_format.load_weights_from_hdf5_group(f, self.layers)

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/tensorflow/python/keras/saving/hdf5_format.py:659, in load_weights_from_hdf5_group(f, layers)
    648 """Implements topological (order-based) weight loading.
    649 
    650 Arguments:
   (...)
    656         and weights file.
    657 """
    658 if 'keras_version' in f.attrs:
--> 659   original_keras_version = f.attrs['keras_version'].decode('utf8')
    660 else:
    661   original_keras_version = '1'

AttributeError: 'str' object has no attribute 'decode'
Skyward
  • 1
  • 1

1 Answers1

0

According to this MSFT document, fixes for Attribute errors such as python AttributeError: 'str' object has no attribute 'decode' are based on the training version of your AutoML SDK

  • You require pandas == 0.25.1 and scikit-learn==0.22.1 , If your AutoML SDK training version is greater than 1.13.0

  • Upgrade scikit-learn and/or pandas to proper version if there is a version discrepancy with the following,

      ```
          pip install --upgrade pandas==0.25.1
          pip install --upgrade scikit-learn==0.22.1
    
      ```
    
  • You require pandas == 0.23.4 and sckit-learn==0.20.3 if your AutoML SDK training version is less than or equal to 1.12.0,

  • Downgrade scikit-learn and/or pandas to correct version with the following, If there is a version mismatch by the following:

      pip install --upgrade pandas==0.23.4
      pip install --upgrade scikit-learn==0.20.3
    

References:

  1. Does Any one got "AttributeError: 'str' object has no attribute 'decode' " , while Loading a Keras Saved Model
    2.azure ml update service erro AttributeError: AttributeError: 'str' object has no attribute 'id'