我是编码新手。我正在尝试获取分数,但不幸的是我遇到了错误。我一直在使用first import.keras直到它给我想要评估分数并进行预测时。训练模型进行得很好,我在那里没有问题。之后,当我很想获得模型的分数时我作为错误ImageDataGnerator获得:对象没有'ndim'。 然后我寻求帮助,有人告诉我改用import.tensorflow.keras,我做到了。...
再次训练模型后,到达该部分以获取分数并在我遇到另一个错误说法后进行预测:ImageDataGenerator对象没有属性形状,并且发出警告: 警告 : 张量流 : 下降 返回 来自 v2 循环 原因是 错误 : 失败 要 查找 数据***适配器 该 可以 处理 输入 : << / strong> 课程 ” tensorflow.python.keras.preprocessing.image.ImageDataGenerator'> , << / strong> 类 “ NoneType” >
这是下面的一些代码。
import numpy as np
import tensorflow as tf
import cv2
import sys
import os
import matplotlib.pyplot as plt
from tensorflow import keras
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten
from tensorflow.keras.layers import Conv2D, MaxPooling2D
from tensorflow.keras.optimizers import Adam
image_width, image_height = 150,150
Epochs =10
batch_size=45
Steps_per_epoch=190
Validation_data=20
num_classes = len(map_characters)
model = Sequential()
model.add(Conv2D(32, (3, 3), padding='same', input_shape= (image_height,image_width ,3)))
model.add(Activation('relu'))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Conv2D(64, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Conv2D(256, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Conv2D(256, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(1024))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
opt = Adam(lr=0.01, decay=1e-6, )
model.summary()
model.compile(loss='categorical_crossentropy',
optimizer='Adam',
metrics=['accuracy'])'''
train_datagen= ImageDataGenerator (
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size = (image_height, image_width),
batch_size = batch_size,
class_mode = 'categorical')
validation_generator = test_datagen.flow_from_directory(
validation_data_dir,
target_size = (image_height, image_width),
batch_size = batch_size,
class_mode = 'categorical')
result=model.fit_generator(training_generator,
steps_per_epoch=Steps_per_epoch,
epochs = Epochs,
validation_data = validation_generator,
validation_steps=Validation_data)
score = model.evaluate(test_datagen,
validation_generator,
batch_size=batch_size)
答案 0 :(得分:0)
要对生成器进行评估,您需要使用evaluate_generator
,而不是evaluate
。