Я пытаюсь запустить этот код, но все еще застрял с этой ошибкой: AttributeError: у объекта 'DirectoryIterator' нет атрибута 'images_ids_in_subset'
, если у кого-то была эта ошибка, и исправьте ее, пожалуйста, дайте мне знать, как выисправил это.
Спасибо
NUM_CLASSES = 2
CHANNELS = 3
IMAGE_RESIZE = 224
RESNET50_POOLING_AVERAGE = 'avg'
DENSE_LAYER_ACTIVATION = 'softmax'
OBJECTIVE_FUNCTION = 'binary_crossentropy'
NUM_EPOCHS = 10
EARLY_STOP_PATIENCE = 3
STEPS_PER_EPOCH_TRAINING = 10
STEPS_PER_EPOCH_VALIDATION = 10
batch_size = 32
from keras.models import load_model
BATCH_SIZE_TRAINING = 100
BATCH_SIZE_VALIDATION = 100
image_size = IMAGE_RESIZE
WEIGHTS_PATH = "C:\\Users\\Desktop\\RESNET\\resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5"
model = Sequential()
train_data_dir = "C:\\Users\\h.mokrane\\Desktop\\RESNET"
model = ResNet50(include_top=True, weights='imagenet')
#Extraction of « Deep Features » ###################
model.layers.pop()
model = Model(input=model.input,output=model.layers[-1].output)
model.summary()
model.compile(loss='binary_crossentropy', optimizer=SGD(lr=0.01, momentum=0.9), metrics= ['binary_accuracy'])
data_dir = "C:\\Users\\Desktop\\RESNET"
data_generator = ImageDataGenerator(preprocessing_function=preprocess_input)
train_datagenerator = ImageDataGenerator(rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
validation_split=0.2)
train_generator = train_datagenerator.flow_from_directory(
train_data_dir,
target_size=(image_size, image_size),
batch_size=BATCH_SIZE_TRAINING,
class_mode='categorical', shuffle=False, subset='training') # set as training data
validation_generator = train_datagenerator.flow_from_directory(
train_data_dir, # same directory as training data kifkif
target_size=(image_size, image_size),
batch_size=BATCH_SIZE_TRAINING,
class_mode='categorical', shuffle=False, subset='validation') # set as validation data
batch_size = 32
save_prefix='', save_format='png', subset=None)
X_train = np.zeros((len(train_generator.images_ids_in_subset),2048))
Y_train = np.zeros((len(train_generator.images_ids_in_subset),2))
Расчет количества партий
nb_batches = int(len(train_generator.images_ids_in_subset) / batch_size) + 1
for i in range(nb_batches):
X, y = next(train_generator)
y_pred = model.predict(X)
X_train[i*batch_size:(i+1)*batch_size,:] = y_pred
Y_train[i*batch_size:(i+1)*batch_size,:] = y
X_test = np.zeros((len(train_generator.images_ids_in_subset),2048))
Y_test = np.zeros((len(train_generator.images_ids_in_subset),2))
nb_batches = int(len(train_generator.images_ids_in_subset) / batch_size) + 1
for i in range(nb_batches):
X, y = next(train_generator)
y_pred = model.predict(X)
X_test[i*batch_size:(i+1)*batch_size,:] = y_pred
Y_test[i*batch_size:(i+1)*batch_size,:] = y
outfile = 'C:\\Users\\Desktop\\RESNET'
np.savez(outfile, X_train=X_train, Y_train=Y_train,X_test=X_test, Y_test=Y_test)