[英]name "model" is not defined Keras
I have this error while saving mode:保存模式时出现此错误:
NameError Traceback (most recent call last) in () ----> 1 Model.save(model, filepath="image_ocr/model.h5") NameError Traceback (last last call last) in () ----> 1 Model.save(model, filepath="image_ocr/model.h5")
NameError: name 'model' is not defined NameError:名称“模型”未定义
//imports:
from keras.models import load_model
from keras.models import Model
import os
import itertools
import codecs
import re
import datetime
import cairocffi as cairo
import editdistance
import numpy as np
from scipy import ndimage
import pylab
from keras import backend as K
from keras.layers.convolutional import Conv2D, MaxPooling2D
from keras.layers import Input, Dense, Activation
from keras.layers import Reshape, Lambda
from keras.layers.merge import add, concatenate
from keras.layers.recurrent import GRU
from keras.optimizers import SGD
from keras.utils.data_utils import get_file
from keras.preprocessing import image
import keras.callbacks
//training model
Model.save("model.h5")
Error is only in last line, but I use 'model' earlier without any errors.错误仅在最后一行,但我之前使用“模型”没有任何错误。 I can't understand where is error.我无法理解错误在哪里。
Since you didn't post the full script of your code, it's hard to tell which line causes the problem.由于您没有发布代码的完整脚本,因此很难判断是哪一行导致了问题。 Based on my experience, similar error messages may arise when saving or loading model commands are mistakenly formulated.根据我的经验,当错误地制定保存或加载模型命令时,可能会出现类似的错误消息。 For example, check the .h5 file is a string enclosed by quotation mark when you formulate the model saving line like例如,当您制定模型保存行时,请检查 .h5 文件是用引号括起来的字符串,例如
model.save("my_model.h5")
As for resolution for errors that arise in the model loading part, check if your custom_object
is clearly defined.至于模型加载部分出现的错误的解决方法,请检查您的custom_object
是否已明确定义。 Hope this is useful.希望这是有用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.