简体   繁体   中英

How to solve error while loading model with keras

I have a flask app, and i am using tensorflow and keras to load the model that i am going to use.Below is a code snippet

from tensorflow.keras.models import Model , load_model
from keras.preprocessing import image

# Flask utils
from flask import Flask, redirect, url_for, request, render_template
from werkzeug.utils import secure_filename
from gevent.pywsgi import WSGIServer

app = Flask(__name__)


Model= load_model('models/model_pro1.h5') 

so i then deploy the flask app on heroku and it builds successfully, but when i check the logs i see that i get an error image for the heroku logs I have tried installing both tensorflow and keras with out a particular version in the requirements.txt file but not getting it solved. I want to know what i am not doing right, and thanks in advance. I am using code from this github repo github repo

Beginning with Python 3, all strings are unicode by default. So i think your dev environment, where you built and trained the models is running python2 while the heroku env has python3.

I'll give an instance of saving a model and then loading it

import tensorflow as tf
from tensorflow import keras
model.save(./abc.h5  # saves in h5 format)
model.save(./defg)#defg is a folder having pb file 

To load the saved model,

new_model = tf.keras.models.load_model('./abc.h5') #for loading h5 model

or

new_model = tf.keras.models.load_model('defg/) # for loading pb model

I think your syntax of load_model is the mistake you committed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM