'Not able to import saved keras model from load_model in VSCode
I trained a keras model on Colab to predict skin diseases from images and when I try to call the model through VSCode, I get the following error.
File "e:/github/Skin_Disease_Assessment/app.py", line 7, in <module>
from keras.preprocessing import image
File "C:\Users\Dilrose\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\__init__.py", line 25, in <module>
from keras import models
File "C:\Users\Dilrose\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\models.py", line 19, in <module>
from keras import backend
File "C:\Users\Dilrose\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend.py", line 301, in <module>
tf.__internal__.register_clear_session_function(clear_session)
AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function'
I'm able to predict the disease when I give images on Colab but since my project is a web application, I want the users to input the image through html and get the answer as well on the website.
My Python code
from flask import Flask, render_template, request, flash, redirect, session, url_for
from sqlite3 import *
from flask import request
from keras.models import load_model
from keras.preprocessing import image
import cv2
import requests
app = Flask(__name__)
app.secret_key = 'abc'
@app.route("/skinExam", methods=["GET", "POST"])
def skinExam():
if request.method == 'POST':
f = request.files['file']
path='static/data/'+ f.filename
f.save(path)
model = load_model('models/final_mobilenet.h5')
img1 = image.load_img(f, target_size=(224,224))
img = cv2.resize(img1, (224,224)) / 255.0
prediction = model.predict(img.reshape(1,224,224,3))
return render_template('skinExam.html')
My HTML code
<div class="col-md-6" style='margin-left:250px;'>
<form class="form-group" action="/skinExam" method='post' enctype="multipart/form-data">
<label>Upload Image</label>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-default btn-file">
Browse… <input type="file" id="imgInp" name="file">
</span>
</span>
<input type="text" class="form-control" readonly>
</div>
<input type='submit' id='upload' class='btn btn-lg btn-success' value='Upload'>
</form>
</div>
Can someone help me in resolving this issue please?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
