ValueError: No model found in config file.

Adesoji Alu asked 2 months ago

2021-03-02 09:42:54.243643: I tensorflow/stream_executor/platform/default/] Successfully opened dynamic library cudart64_110.dll
Traceback (most recent call last):
File "C:\Users\Sortol\Downloads\Compressed\AIFlowers2-master\", line 19, in
model = load_model(model_path)
File "C:\Users\Sortol\anaconda3\lib\site-packages\tensorflow\python\keras\saving\", 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\", 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
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)

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__)

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)
result = predict(file_path)
if result == 0:
label = ‘Daisy’
elif result == 1:
label = ‘Rose’
elif result == 2:
label = ‘Sunflowers’
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

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

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

if __name__ == “__main__”:
app.debug=False’′, 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 =