简体   繁体   English

AttributeError: 'ImageDataGenerator' 对象没有属性 'shape'

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

相关问题 错误:“ImageDataGenerator”对象没有“shape”属性 - Error: 'ImageDataGenerator' object has no attribute 'shape' Python Keras ImageDataGenerator:AttributeError:&#39;super&#39;对象没有属性&#39;init&#39; - Python Keras ImageDataGenerator: AttributeError: 'super' object has no attribute 'init' AttributeError: &#39;float&#39; 对象没有属性 &#39;shape&#39; - AttributeError: 'float' object has no attribute 'shape' AttributeError:&#39;tuple&#39;对象没有属性&#39;shape&#39; - AttributeError: 'tuple' object has no attribute 'shape' TensorFlow:AttributeError:&#39;Tensor&#39;对象没有属性&#39;shape&#39; - TensorFlow: AttributeError: 'Tensor' object has no attribute 'shape' AttributeError: &#39;Concatenate&#39; 对象没有属性 &#39;shape&#39; - AttributeError: 'Concatenate' object has no attribute 'shape' AttributeError: &#39;str&#39; 对象没有属性 &#39;shape&#39; - AttributeError: 'str' object has no attribute 'shape' AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;shape&#39; - AttributeError: 'NoneType' object has no attribute 'shape' AttributeError:&#39;Tensor&#39;对象没有属性&#39;shape&#39; - AttributeError: 'Tensor' object has no attribute 'shape' AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;shape&#39; FLASK - AttributeError: 'NoneType' object has no attribute 'shape' FLASK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM