[英]AttributeError: 'ImageDataGenerator' object has no attribute 'shape'
I am new in coding.我是编码新手。 I am trying to get the score but unfortunately i am getting errors.我正在尝试获得分数,但不幸的是我遇到了错误。 I was using first import.keras until it gave me when i wanted to evaluate the score and predict.The training model happened well, i have gotten no problem there.It is after that, when i was aboout to get the score of my model that i got as error ImageDataGnerator: Object has no 'ndim'.我第一次使用 import.keras 直到我想评估分数和预测时它给了我。训练模型进行得很好,我在那里没有问题。在那之后,当我即将获得我的模型的分数时我得到的错误 ImageDataGneror: Object has no 'ndim'。 Then i looked for help and someone told me to use import.tensorflow.keras instead and i did it....然后我寻求帮助,有人告诉我改用 import.tensorflow.keras,我做到了....
After training the model again,reaching that part in order to get the score and predict after i've gotten another error saying : ImageDataGenerator object has no attribute shapes and a warning saying : WARNING : tensorflow : Falling back from v2 loop because of error : Failed to find data* **adapter that can handle input : < class 'tensorflow.python.keras.preprocessing.image.ImageDataGenerator'> , < class 'NoneType' ImageDataGenerator对象没有任何属性的形状和警告提示:警告:tensorflow:从因错误的V2环落回来训练模型,达到这部分以获得分数和预测我已经得到了另一个错误说之后:未能找到数据* **适配器可以处理输入:<类“tensorflow.python.keras.preprocessing.image.ImageDataGenerator”>,<类“NoneType”
This is some of the code below.这是下面的一些代码。
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)
要评估生成器,您需要使用evaluate_generator
,而不是evaluate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.