AttributeError: 'str' object has no attribute 'decode' Can anybody please help me with this error. I am unable to clear it

AttributeError: ‘str’ object has no attribute ‘decode’


  File "/app/.heroku/python/lib/python3.6/site-packages/streamlit/", line 324, in _run_script
    exec(code, module.__dict__)
  File "/app/", line 23, in <module>
    label = teachable_machine_classification(image, 'brain_tumor_classification.h5')
  File "/app/", line 8, in teachable_machine_classification
    model = keras.models.load_model("./keras_model.h5", compile=False)
  File "/app/.heroku/python/lib/python3.6/site-packages/tensorflow/python/keras/saving/", line 182, in load_model
    return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
  File "/app/.heroku/python/lib/python3.6/site-packages/tensorflow/python/keras/saving/", line 176, in load_model_from_hdf5
    model_config = json.loads(model_config.decode('utf-8'))

This is the code i am running:

import keras
from PIL import Image, ImageOps
import numpy as np

def teachable_machine_classification(img, weights_file):
    # Load the model
    model = keras.models.load_model("./keras_model.h5", compile=False)

    # Create the array of the right shape to feed into the keras model
    data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
    image = img
    #image sizing
    size = (224, 224)
    image =, size, Image.ANTIALIAS)

    #turn the image into a numpy array
    image_array = np.asarray(image)
    # Normalize the image
    normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1

    # Load the image into the array
    data[0] = normalized_image_array

    # run the inference
    prediction = model.predict(data)
    return np.argmax(prediction) # return position of the highest probability

import streamlit as st
from img_classification import teachable_machine_classification
from PIL import Image
import webbrowser

url = ''

st.title("Image Classification with Google's Teachable Machine")
st.header("Brain Tumor MRI Classification Example")
st.text("Upload a brain MRI Image for image classification as tumor or no-tumor")
if st.button('Dataset From Here'):

uploaded_file = st.file_uploader("Choose a brain MRI ...", type="jpg")
if uploaded_file is not None:
    image =
    st.image(image, caption='Uploaded MRI.', use_column_width=True)
    label = teachable_machine_classification(image, 'brain_tumor_classification.h5')
    if label == 0:
        st.write("The MRI scan has a brain tumor")
        st.write("The MRI scan is healthy")

Hi @notmyfaultok12345678 I have worked on a tutorial for this. Probably it could help you:

Let me know if it works for you.