ValueError: No model found in config file.

Adesoji Alu asked 2 months ago


C:\Users\Sortol>c:\Users\Sortol\Downloads\Compressed\AIFlowers2-master\app.py
2021-03-02 09:42:54.243643: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
Traceback (most recent call last):
File "C:\Users\Sortol\Downloads\Compressed\AIFlowers2-master\app.py", line 19, in
model = load_model(model_path)
File "C:\Users\Sortol\anaconda3\lib\site-packages\tensorflow\python\keras\saving\save.py", line 206, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects,
File "C:\Users\Sortol\anaconda3\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py", line 181, in load_model_from_hdf5
raise ValueError('No model found in config file.')
ValueError: No model found in config file.

The code below

#Usage: python app.py
import os

from flask import Flask, render_template, request, redirect, url_for
from werkzeug.utils import secure_filename
from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
from keras.models import Sequential, load_model
import numpy as np
import argparse
import imutils
import cv2
import time
import uuid
import base64

img_width, img_height = 150, 150
model_path = r”C:\Users\Sortol\Desktop\TASK\models\plantmodel.h5″
model_weights_path = r”C:\Users\Sortol\Desktop\TASK\my_model_weights.h5″
model = load_model(model_path)
model.load_weights(model_weights_path)

UPLOAD_FOLDER = ‘uploads’
ALLOWED_EXTENSIONS = set([‘jpg’, ‘jpeg’])

def get_as_base64(url):
return base64.b64encode(request.get(url).content)

def predict(file):
x = load_img(file, target_size=(img_width,img_height))
x = img_to_array(x)
x = np.expand_dims(x, axis=0)
array = model.predict(x)
result = array[0]
answer = np.argmax(result)
if answer == 0:
print(“Label: Daisy”)
elif answer == 1:
print(“Label: Rose”)
elif answer == 2:
print(“Label: Sunflower”)
return answer

def my_random_string(string_length=10):
“””Returns a random string of length string_length.”””
random = str(uuid.uuid4()) # Convert UUID format to a Python string.
random = random.upper() # Make all characters uppercase.
random = random.replace(“-“,””) # Remove the UUID ‘-‘.
return random[0:string_length] # Return the random string.

def allowed_file(filename):
return ‘.’ in filename and \
filename.rsplit(‘.’, 1)[1] in ALLOWED_EXTENSIONS

app = Flask(__name__)
app.config[‘UPLOAD_FOLDER’] = UPLOAD_FOLDER

@app.route(“/”)
def template_test():
return render_template(‘template.html’, label=”, imagesource=’../uploads/template.jpg’)

@app.route(‘/’, methods=[‘GET’, ‘POST’])
def upload_file():
if request.method == ‘POST’:
import time
start_time = time.time()
file = request.files[‘file’]

if file and allowed_file(file.filename):
filename = secure_filename(file.filename)

file_path = os.path.join(app.config[‘UPLOAD_FOLDER’], filename)
file.save(file_path)
result = predict(file_path)
if result == 0:
label = ‘Daisy’
elif result == 1:
label = ‘Rose’
elif result == 2:
label = ‘Sunflowers’
print(result)
print(file_path)
filename = my_random_string(6) + filename

Let's pause for a second! 👩‍💻

Blogs at MachineCurve teach Machine Learning for Developers. Sign up to MachineCurve's free Machine Learning update today! You will learn new things and better understand concepts you already know.

We send emails at least every Friday. Welcome!

By signing up, you consent that any information you receive can include services and special offers by email.

os.rename(file_path, os.path.join(app.config[‘UPLOAD_FOLDER’], filename))
print(“— %s seconds —” % str (time.time() – start_time))
return render_template(‘template.html’, label=label, imagesource=’../uploads/’ + filename)

from flask import send_from_directory

@app.route(‘/uploads/’)
def uploaded_file(filename):
return send_from_directory(app.config[‘UPLOAD_FOLDER’],
filename)

from werkzeug import SharedDataMiddleware
app.add_url_rule(‘/uploads/’, ‘uploaded_file’,
build_only=True)
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
‘/uploads’: app.config[‘UPLOAD_FOLDER’]
})

if __name__ == “__main__”:
app.debug=False
app.run(host=’0.0.0.0′, port=3000)

2 Answers
Best Answer
Chris Staff answered 2 months ago

Is there a model at the model_path that you specified?
For example, it might work if you change the \ symbols into /.

Adesoji answered 2 months ago

there wasn’t.Thanks sir

Your Answer

8 + 14 =