Unable to load a model using load_model()





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















All the below imports are executed without any error



import cv2
import numpy as np
import dlib
import glob
from scipy.spatial import distance
from imutils import face_utils
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *


When I try to import a pre trained model 'face-rec_Google.h5' which has been trained using facenet. The file('face-rec_Google.h5') is in my project folder.



x = load_model('face-rec_Google.h5')


I am getting the following error



ValueError: Initializer for variable conv1_4/kernel/ is from inside a 
control-flow construct, such as a loop or conditional. When creating a
variable inside a loop or conditional,
use a lambda as the initializer.


here's the entire face recognition code:



import cv2
import numpy as np
import dlib
import glob
from scipy.spatial import distance
from imutils import face_utils
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *

detector = dlib.get_frontal_face_detector()

x = load_model('face-rec_Google.h5')
print("Total Params:", x.count_params())
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
thresh = 0.25


def eye_aspect_ratio(eye):
A = distance.euclidean(eye[1], eye[5])
B = distance.euclidean(eye[2], eye[4])
C = distance.euclidean(eye[0], eye[3])
ear = (A + B) / (2.0 * C)
return ear

def recognize_face(face_descriptor, database):
encoding = img_to_encoding(face_descriptor, FRmodel)
min_dist = 100
identity = None

# Loop over the database dictionary's names and encodings.
for (name, db_enc) in database.items():

# Compute L2 distance between the target "encoding" and the current "emb" from the database.
dist = np.linalg.norm(db_enc - encoding)

print('distance for %s is %s' % (name, dist))

# If this distance is less than the min_dist, then set min_dist to dist, and identity to name
if dist < min_dist:
min_dist = dist
identity = name

if int(identity) <=4:
return str('Akshay'), min_dist
if int(identity) <=8:
return str('Apoorva'), min_dist



def extract_face_info(img, img_rgb, database,ear):
faces = detector(img_rgb)
x, y, w, h = 0, 0, 0, 0
if len(faces) > 0:
for face in faces:
(x, y, w, h) = face_utils.rect_to_bb(face)
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 2)
image = img[y:y + h, x:x + w]
name, min_dist = recognize_face(image, database)
if ear > thresh:
if min_dist < 0.1:
cv2.putText(img, "Face : " + name, (x, y - 50), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
cv2.putText(img, "Dist : " + str(min_dist), (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
else:
cv2.putText(img, 'No matching faces', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)
else:
cv2.putText(img, 'Eyes Closed', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)

def initialize():
#load_weights_from_FaceNet(FRmodel)
#we are loading model from keras hence we won't use the above method
database = {}

# load all the images of individuals to recognize into the database
for file in glob.glob("images//"):
identity = os.path.splitext(os.path.basename(file))[0]
database[identity] = fr_utils.img_path_to_encoding(file, FRmodel)
return database


def recognize():
database = initialize()
cap = cv2.VideoCapture(0)
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
while True:
ret, img = cap.read()
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
subjects = detector(gray, 0)
for subject in subjects:
shape = predictor(gray, subject)
shape = face_utils.shape_to_np(shape) # converting to NumPy Array
leftEye = shape[lStart:lEnd]
rightEye = shape[rStart:rEnd]
leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)
ear = (leftEAR + rightEAR) / 2.0
leftEyeHull = cv2.convexHull(leftEye)
rightEyeHull = cv2.convexHull(rightEye)
cv2.drawContours(img, [leftEyeHull], -1, (0, 255, 0), 1)
cv2.drawContours(img, [rightEyeHull], -1, (0, 255, 0), 1)
extract_face_info(img, img_rgb, database,ear)
cv2.imshow('Recognizing faces', img)
if cv2.waitKey(1) == ord('q'):
break

cap.release()
cv2.destroyAllWindows()


recognize()









share|improve this question

























  • Can you include the full traceback of the error?

    – Matias Valdenegro
    Jan 3 at 13:24


















0















All the below imports are executed without any error



import cv2
import numpy as np
import dlib
import glob
from scipy.spatial import distance
from imutils import face_utils
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *


When I try to import a pre trained model 'face-rec_Google.h5' which has been trained using facenet. The file('face-rec_Google.h5') is in my project folder.



x = load_model('face-rec_Google.h5')


I am getting the following error



ValueError: Initializer for variable conv1_4/kernel/ is from inside a 
control-flow construct, such as a loop or conditional. When creating a
variable inside a loop or conditional,
use a lambda as the initializer.


here's the entire face recognition code:



import cv2
import numpy as np
import dlib
import glob
from scipy.spatial import distance
from imutils import face_utils
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *

detector = dlib.get_frontal_face_detector()

x = load_model('face-rec_Google.h5')
print("Total Params:", x.count_params())
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
thresh = 0.25


def eye_aspect_ratio(eye):
A = distance.euclidean(eye[1], eye[5])
B = distance.euclidean(eye[2], eye[4])
C = distance.euclidean(eye[0], eye[3])
ear = (A + B) / (2.0 * C)
return ear

def recognize_face(face_descriptor, database):
encoding = img_to_encoding(face_descriptor, FRmodel)
min_dist = 100
identity = None

# Loop over the database dictionary's names and encodings.
for (name, db_enc) in database.items():

# Compute L2 distance between the target "encoding" and the current "emb" from the database.
dist = np.linalg.norm(db_enc - encoding)

print('distance for %s is %s' % (name, dist))

# If this distance is less than the min_dist, then set min_dist to dist, and identity to name
if dist < min_dist:
min_dist = dist
identity = name

if int(identity) <=4:
return str('Akshay'), min_dist
if int(identity) <=8:
return str('Apoorva'), min_dist



def extract_face_info(img, img_rgb, database,ear):
faces = detector(img_rgb)
x, y, w, h = 0, 0, 0, 0
if len(faces) > 0:
for face in faces:
(x, y, w, h) = face_utils.rect_to_bb(face)
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 2)
image = img[y:y + h, x:x + w]
name, min_dist = recognize_face(image, database)
if ear > thresh:
if min_dist < 0.1:
cv2.putText(img, "Face : " + name, (x, y - 50), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
cv2.putText(img, "Dist : " + str(min_dist), (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
else:
cv2.putText(img, 'No matching faces', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)
else:
cv2.putText(img, 'Eyes Closed', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)

def initialize():
#load_weights_from_FaceNet(FRmodel)
#we are loading model from keras hence we won't use the above method
database = {}

# load all the images of individuals to recognize into the database
for file in glob.glob("images//"):
identity = os.path.splitext(os.path.basename(file))[0]
database[identity] = fr_utils.img_path_to_encoding(file, FRmodel)
return database


def recognize():
database = initialize()
cap = cv2.VideoCapture(0)
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
while True:
ret, img = cap.read()
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
subjects = detector(gray, 0)
for subject in subjects:
shape = predictor(gray, subject)
shape = face_utils.shape_to_np(shape) # converting to NumPy Array
leftEye = shape[lStart:lEnd]
rightEye = shape[rStart:rEnd]
leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)
ear = (leftEAR + rightEAR) / 2.0
leftEyeHull = cv2.convexHull(leftEye)
rightEyeHull = cv2.convexHull(rightEye)
cv2.drawContours(img, [leftEyeHull], -1, (0, 255, 0), 1)
cv2.drawContours(img, [rightEyeHull], -1, (0, 255, 0), 1)
extract_face_info(img, img_rgb, database,ear)
cv2.imshow('Recognizing faces', img)
if cv2.waitKey(1) == ord('q'):
break

cap.release()
cv2.destroyAllWindows()


recognize()









share|improve this question

























  • Can you include the full traceback of the error?

    – Matias Valdenegro
    Jan 3 at 13:24














0












0








0








All the below imports are executed without any error



import cv2
import numpy as np
import dlib
import glob
from scipy.spatial import distance
from imutils import face_utils
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *


When I try to import a pre trained model 'face-rec_Google.h5' which has been trained using facenet. The file('face-rec_Google.h5') is in my project folder.



x = load_model('face-rec_Google.h5')


I am getting the following error



ValueError: Initializer for variable conv1_4/kernel/ is from inside a 
control-flow construct, such as a loop or conditional. When creating a
variable inside a loop or conditional,
use a lambda as the initializer.


here's the entire face recognition code:



import cv2
import numpy as np
import dlib
import glob
from scipy.spatial import distance
from imutils import face_utils
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *

detector = dlib.get_frontal_face_detector()

x = load_model('face-rec_Google.h5')
print("Total Params:", x.count_params())
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
thresh = 0.25


def eye_aspect_ratio(eye):
A = distance.euclidean(eye[1], eye[5])
B = distance.euclidean(eye[2], eye[4])
C = distance.euclidean(eye[0], eye[3])
ear = (A + B) / (2.0 * C)
return ear

def recognize_face(face_descriptor, database):
encoding = img_to_encoding(face_descriptor, FRmodel)
min_dist = 100
identity = None

# Loop over the database dictionary's names and encodings.
for (name, db_enc) in database.items():

# Compute L2 distance between the target "encoding" and the current "emb" from the database.
dist = np.linalg.norm(db_enc - encoding)

print('distance for %s is %s' % (name, dist))

# If this distance is less than the min_dist, then set min_dist to dist, and identity to name
if dist < min_dist:
min_dist = dist
identity = name

if int(identity) <=4:
return str('Akshay'), min_dist
if int(identity) <=8:
return str('Apoorva'), min_dist



def extract_face_info(img, img_rgb, database,ear):
faces = detector(img_rgb)
x, y, w, h = 0, 0, 0, 0
if len(faces) > 0:
for face in faces:
(x, y, w, h) = face_utils.rect_to_bb(face)
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 2)
image = img[y:y + h, x:x + w]
name, min_dist = recognize_face(image, database)
if ear > thresh:
if min_dist < 0.1:
cv2.putText(img, "Face : " + name, (x, y - 50), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
cv2.putText(img, "Dist : " + str(min_dist), (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
else:
cv2.putText(img, 'No matching faces', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)
else:
cv2.putText(img, 'Eyes Closed', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)

def initialize():
#load_weights_from_FaceNet(FRmodel)
#we are loading model from keras hence we won't use the above method
database = {}

# load all the images of individuals to recognize into the database
for file in glob.glob("images//"):
identity = os.path.splitext(os.path.basename(file))[0]
database[identity] = fr_utils.img_path_to_encoding(file, FRmodel)
return database


def recognize():
database = initialize()
cap = cv2.VideoCapture(0)
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
while True:
ret, img = cap.read()
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
subjects = detector(gray, 0)
for subject in subjects:
shape = predictor(gray, subject)
shape = face_utils.shape_to_np(shape) # converting to NumPy Array
leftEye = shape[lStart:lEnd]
rightEye = shape[rStart:rEnd]
leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)
ear = (leftEAR + rightEAR) / 2.0
leftEyeHull = cv2.convexHull(leftEye)
rightEyeHull = cv2.convexHull(rightEye)
cv2.drawContours(img, [leftEyeHull], -1, (0, 255, 0), 1)
cv2.drawContours(img, [rightEyeHull], -1, (0, 255, 0), 1)
extract_face_info(img, img_rgb, database,ear)
cv2.imshow('Recognizing faces', img)
if cv2.waitKey(1) == ord('q'):
break

cap.release()
cv2.destroyAllWindows()


recognize()









share|improve this question
















All the below imports are executed without any error



import cv2
import numpy as np
import dlib
import glob
from scipy.spatial import distance
from imutils import face_utils
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *


When I try to import a pre trained model 'face-rec_Google.h5' which has been trained using facenet. The file('face-rec_Google.h5') is in my project folder.



x = load_model('face-rec_Google.h5')


I am getting the following error



ValueError: Initializer for variable conv1_4/kernel/ is from inside a 
control-flow construct, such as a loop or conditional. When creating a
variable inside a loop or conditional,
use a lambda as the initializer.


here's the entire face recognition code:



import cv2
import numpy as np
import dlib
import glob
from scipy.spatial import distance
from imutils import face_utils
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *

detector = dlib.get_frontal_face_detector()

x = load_model('face-rec_Google.h5')
print("Total Params:", x.count_params())
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
thresh = 0.25


def eye_aspect_ratio(eye):
A = distance.euclidean(eye[1], eye[5])
B = distance.euclidean(eye[2], eye[4])
C = distance.euclidean(eye[0], eye[3])
ear = (A + B) / (2.0 * C)
return ear

def recognize_face(face_descriptor, database):
encoding = img_to_encoding(face_descriptor, FRmodel)
min_dist = 100
identity = None

# Loop over the database dictionary's names and encodings.
for (name, db_enc) in database.items():

# Compute L2 distance between the target "encoding" and the current "emb" from the database.
dist = np.linalg.norm(db_enc - encoding)

print('distance for %s is %s' % (name, dist))

# If this distance is less than the min_dist, then set min_dist to dist, and identity to name
if dist < min_dist:
min_dist = dist
identity = name

if int(identity) <=4:
return str('Akshay'), min_dist
if int(identity) <=8:
return str('Apoorva'), min_dist



def extract_face_info(img, img_rgb, database,ear):
faces = detector(img_rgb)
x, y, w, h = 0, 0, 0, 0
if len(faces) > 0:
for face in faces:
(x, y, w, h) = face_utils.rect_to_bb(face)
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 2)
image = img[y:y + h, x:x + w]
name, min_dist = recognize_face(image, database)
if ear > thresh:
if min_dist < 0.1:
cv2.putText(img, "Face : " + name, (x, y - 50), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
cv2.putText(img, "Dist : " + str(min_dist), (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
else:
cv2.putText(img, 'No matching faces', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)
else:
cv2.putText(img, 'Eyes Closed', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)

def initialize():
#load_weights_from_FaceNet(FRmodel)
#we are loading model from keras hence we won't use the above method
database = {}

# load all the images of individuals to recognize into the database
for file in glob.glob("images//"):
identity = os.path.splitext(os.path.basename(file))[0]
database[identity] = fr_utils.img_path_to_encoding(file, FRmodel)
return database


def recognize():
database = initialize()
cap = cv2.VideoCapture(0)
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
while True:
ret, img = cap.read()
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
subjects = detector(gray, 0)
for subject in subjects:
shape = predictor(gray, subject)
shape = face_utils.shape_to_np(shape) # converting to NumPy Array
leftEye = shape[lStart:lEnd]
rightEye = shape[rStart:rEnd]
leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)
ear = (leftEAR + rightEAR) / 2.0
leftEyeHull = cv2.convexHull(leftEye)
rightEyeHull = cv2.convexHull(rightEye)
cv2.drawContours(img, [leftEyeHull], -1, (0, 255, 0), 1)
cv2.drawContours(img, [rightEyeHull], -1, (0, 255, 0), 1)
extract_face_info(img, img_rgb, database,ear)
cv2.imshow('Recognizing faces', img)
if cv2.waitKey(1) == ord('q'):
break

cap.release()
cv2.destroyAllWindows()


recognize()






python opencv keras face-recognition dlib






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 13:25









Matias Valdenegro

32.5k45782




32.5k45782










asked Jan 3 at 7:31









abhinay ojaabhinay oja

82




82













  • Can you include the full traceback of the error?

    – Matias Valdenegro
    Jan 3 at 13:24



















  • Can you include the full traceback of the error?

    – Matias Valdenegro
    Jan 3 at 13:24

















Can you include the full traceback of the error?

– Matias Valdenegro
Jan 3 at 13:24





Can you include the full traceback of the error?

– Matias Valdenegro
Jan 3 at 13:24












1 Answer
1






active

oldest

votes


















0














What Keras version are you using?



One suggestion I would make is to try to update Keras to its latest version(2.2.4 at the time of writing this comment).



Make sure you also update keras.applications and keras.preprocessing to their latest version.



If this does not work, you could try the following option:



First uninstall Keras and its applications+preprocessing(I forgot to add this, sorry)



Then, update the version of your TensorFlow. After this step, follow the suggestion below.



Try using the load_model method via tensorflow.
Ex: from tensorflow.keras.models import load_model






share|improve this answer


























  • Here are my dependencies Keras -2.2.4 ,Keras-Applications -1.0.6 Keras-Preprocessing -1.0.5 tensorflow-1.8 from tensorflow.keras.models import load_model results in ModuleNotFoundError

    – abhinay oja
    Jan 3 at 11:03













  • Try uninstalling Keras. Since Keras is now a part of tensorflow backend, you should not need Keras installed separately. Upgrade TensorFlow and uninstall Keras.

    – Timbus Calin
    Jan 3 at 12:46













  • Also, make sure you import everything in the same manner; example : instead of keras.x use tensorflow.keras.x

    – Timbus Calin
    Jan 3 at 15:11











  • Thanks man it worked forgot to rename tensorflow.keras my other files so the error persisted for a while

    – abhinay oja
    Jan 3 at 17:45











  • No problem, I am very happy that it solved your issue! :D

    – Timbus Calin
    Jan 3 at 19:47












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018085%2funable-to-load-a-model-using-load-model%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














What Keras version are you using?



One suggestion I would make is to try to update Keras to its latest version(2.2.4 at the time of writing this comment).



Make sure you also update keras.applications and keras.preprocessing to their latest version.



If this does not work, you could try the following option:



First uninstall Keras and its applications+preprocessing(I forgot to add this, sorry)



Then, update the version of your TensorFlow. After this step, follow the suggestion below.



Try using the load_model method via tensorflow.
Ex: from tensorflow.keras.models import load_model






share|improve this answer


























  • Here are my dependencies Keras -2.2.4 ,Keras-Applications -1.0.6 Keras-Preprocessing -1.0.5 tensorflow-1.8 from tensorflow.keras.models import load_model results in ModuleNotFoundError

    – abhinay oja
    Jan 3 at 11:03













  • Try uninstalling Keras. Since Keras is now a part of tensorflow backend, you should not need Keras installed separately. Upgrade TensorFlow and uninstall Keras.

    – Timbus Calin
    Jan 3 at 12:46













  • Also, make sure you import everything in the same manner; example : instead of keras.x use tensorflow.keras.x

    – Timbus Calin
    Jan 3 at 15:11











  • Thanks man it worked forgot to rename tensorflow.keras my other files so the error persisted for a while

    – abhinay oja
    Jan 3 at 17:45











  • No problem, I am very happy that it solved your issue! :D

    – Timbus Calin
    Jan 3 at 19:47
















0














What Keras version are you using?



One suggestion I would make is to try to update Keras to its latest version(2.2.4 at the time of writing this comment).



Make sure you also update keras.applications and keras.preprocessing to their latest version.



If this does not work, you could try the following option:



First uninstall Keras and its applications+preprocessing(I forgot to add this, sorry)



Then, update the version of your TensorFlow. After this step, follow the suggestion below.



Try using the load_model method via tensorflow.
Ex: from tensorflow.keras.models import load_model






share|improve this answer


























  • Here are my dependencies Keras -2.2.4 ,Keras-Applications -1.0.6 Keras-Preprocessing -1.0.5 tensorflow-1.8 from tensorflow.keras.models import load_model results in ModuleNotFoundError

    – abhinay oja
    Jan 3 at 11:03













  • Try uninstalling Keras. Since Keras is now a part of tensorflow backend, you should not need Keras installed separately. Upgrade TensorFlow and uninstall Keras.

    – Timbus Calin
    Jan 3 at 12:46













  • Also, make sure you import everything in the same manner; example : instead of keras.x use tensorflow.keras.x

    – Timbus Calin
    Jan 3 at 15:11











  • Thanks man it worked forgot to rename tensorflow.keras my other files so the error persisted for a while

    – abhinay oja
    Jan 3 at 17:45











  • No problem, I am very happy that it solved your issue! :D

    – Timbus Calin
    Jan 3 at 19:47














0












0








0







What Keras version are you using?



One suggestion I would make is to try to update Keras to its latest version(2.2.4 at the time of writing this comment).



Make sure you also update keras.applications and keras.preprocessing to their latest version.



If this does not work, you could try the following option:



First uninstall Keras and its applications+preprocessing(I forgot to add this, sorry)



Then, update the version of your TensorFlow. After this step, follow the suggestion below.



Try using the load_model method via tensorflow.
Ex: from tensorflow.keras.models import load_model






share|improve this answer















What Keras version are you using?



One suggestion I would make is to try to update Keras to its latest version(2.2.4 at the time of writing this comment).



Make sure you also update keras.applications and keras.preprocessing to their latest version.



If this does not work, you could try the following option:



First uninstall Keras and its applications+preprocessing(I forgot to add this, sorry)



Then, update the version of your TensorFlow. After this step, follow the suggestion below.



Try using the load_model method via tensorflow.
Ex: from tensorflow.keras.models import load_model







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 12:48

























answered Jan 3 at 10:00









Timbus CalinTimbus Calin

637




637













  • Here are my dependencies Keras -2.2.4 ,Keras-Applications -1.0.6 Keras-Preprocessing -1.0.5 tensorflow-1.8 from tensorflow.keras.models import load_model results in ModuleNotFoundError

    – abhinay oja
    Jan 3 at 11:03













  • Try uninstalling Keras. Since Keras is now a part of tensorflow backend, you should not need Keras installed separately. Upgrade TensorFlow and uninstall Keras.

    – Timbus Calin
    Jan 3 at 12:46













  • Also, make sure you import everything in the same manner; example : instead of keras.x use tensorflow.keras.x

    – Timbus Calin
    Jan 3 at 15:11











  • Thanks man it worked forgot to rename tensorflow.keras my other files so the error persisted for a while

    – abhinay oja
    Jan 3 at 17:45











  • No problem, I am very happy that it solved your issue! :D

    – Timbus Calin
    Jan 3 at 19:47



















  • Here are my dependencies Keras -2.2.4 ,Keras-Applications -1.0.6 Keras-Preprocessing -1.0.5 tensorflow-1.8 from tensorflow.keras.models import load_model results in ModuleNotFoundError

    – abhinay oja
    Jan 3 at 11:03













  • Try uninstalling Keras. Since Keras is now a part of tensorflow backend, you should not need Keras installed separately. Upgrade TensorFlow and uninstall Keras.

    – Timbus Calin
    Jan 3 at 12:46













  • Also, make sure you import everything in the same manner; example : instead of keras.x use tensorflow.keras.x

    – Timbus Calin
    Jan 3 at 15:11











  • Thanks man it worked forgot to rename tensorflow.keras my other files so the error persisted for a while

    – abhinay oja
    Jan 3 at 17:45











  • No problem, I am very happy that it solved your issue! :D

    – Timbus Calin
    Jan 3 at 19:47

















Here are my dependencies Keras -2.2.4 ,Keras-Applications -1.0.6 Keras-Preprocessing -1.0.5 tensorflow-1.8 from tensorflow.keras.models import load_model results in ModuleNotFoundError

– abhinay oja
Jan 3 at 11:03







Here are my dependencies Keras -2.2.4 ,Keras-Applications -1.0.6 Keras-Preprocessing -1.0.5 tensorflow-1.8 from tensorflow.keras.models import load_model results in ModuleNotFoundError

– abhinay oja
Jan 3 at 11:03















Try uninstalling Keras. Since Keras is now a part of tensorflow backend, you should not need Keras installed separately. Upgrade TensorFlow and uninstall Keras.

– Timbus Calin
Jan 3 at 12:46







Try uninstalling Keras. Since Keras is now a part of tensorflow backend, you should not need Keras installed separately. Upgrade TensorFlow and uninstall Keras.

– Timbus Calin
Jan 3 at 12:46















Also, make sure you import everything in the same manner; example : instead of keras.x use tensorflow.keras.x

– Timbus Calin
Jan 3 at 15:11





Also, make sure you import everything in the same manner; example : instead of keras.x use tensorflow.keras.x

– Timbus Calin
Jan 3 at 15:11













Thanks man it worked forgot to rename tensorflow.keras my other files so the error persisted for a while

– abhinay oja
Jan 3 at 17:45





Thanks man it worked forgot to rename tensorflow.keras my other files so the error persisted for a while

– abhinay oja
Jan 3 at 17:45













No problem, I am very happy that it solved your issue! :D

– Timbus Calin
Jan 3 at 19:47





No problem, I am very happy that it solved your issue! :D

– Timbus Calin
Jan 3 at 19:47




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018085%2funable-to-load-a-model-using-load-model%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith