简体   繁体   English

名称“模型”未定义 Keras

[英]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.

相关问题 尝试运行 Keras 分段 model 称为 PspNet 时出现“NameError: name 'np' is not defined” - “NameError: name 'np' is not defined” when trying to run a Keras segmentation model called PspNet NameError:name 'create_model' is not defined ....我试过从 keras 导入模型但它没有解决它。如何解决? - NameError:name 'create_model' is not defined ....i have tried importing model from keras but it hasnt solved it .how to solve? Keras 教程错误:NameError:未定义名称“层” - Keras Tutorial Error: NameError: name 'layers' is not defined 名称“顺序”未定义 Python3 Keras - name 'Sequential' is not defined Python3 Keras 名称“classification_model”未定义 - name 'classification_model' is not defined NameError:名称“模型”未在python代码中定义用于隔离语音识别 - NameError: name 'model' is not defined in python code for isolated speech recognition 如何修复“NameError: name 'load_model' 未定义” - How to fix"NameError: name 'load_model' is not defined" Django Rest Framework中的NameError,它显示我的模型名称未定义 - NameError in Django Rest Framework, it's showing my model name is not defined convert tensorflow.keras model to keras model - convert tensorflow.keras model to keras model 名称未定义 - Name is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM