''str' object has no attribute 'decode' for tensorflow in colab?
I'm a beginner of deeplearning.I copied the code with python3 in colab. Code is from the book called"Book - Practical Deep Learning for Cloud, Mobile & Edge".link here:https://github.com/PracticalDL/Practical-Deep-Learning-Book/blob/master/code/chapter-2/1-predict-class.ipynb
try:
import google.colab
IS_COLAB_ENV = True
except:
IS_COLAB_ENV = False
IS_COLAB_ENV
if IS_COLAB_ENV:
!pip install -q h5py==2.10.0
!pip install tensorflow==2.0.0
import tensorflow as tf
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
from tensorflow.keras.preprocessing import image
import numpy as np
import matplotlib.pyplot as plt
IMG_PATH = '../../sample-images/cat.jpg'
if IS_COLAB_ENV:
!curl https://raw.githubusercontent.com/PracticalDL/Practical-Deep-Learning-Book/master/sample-images/cat.jpg --output cat.jpg
IMG_PATH = 'cat.jpg'
img = image.load_img(IMG_PATH, target_size=(224, 224))
plt.imshow(img)
plt.show()
model = tf.keras.applications.resnet50.ResNet50() #stopped
And the errors are like this
AttributeError Traceback (most recent call last)
<ipython-input-18-7e626296379d> in <module>()
----> 1 model = tf.keras.applications.resnet50.ResNet50()
6 frames
/usr/local/lib/python3.7/dist-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'
All examples in this book have this error. I found an answer like"add this:!pip install -q h5py==2.10.0", but it didn't work for me. Does anyone know how to solve it?I look forward to someone answering my questions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|