tensorflow не принемается генератор генератор

'NoneType' object is not callable

у меня сеть принимающая картинки и выдающая лейбл и баундбокса координаты. я долго пытался подать в генератор встроенный данные с датафрейма и не получилось. данные вроде загружает генератор, но правильно никак не могут распределиться в сеть и ошибку выдает. решил сам написать генератор, но так же не работает( картинку принимает вроде. сперва выдавало ошибку типо 4го измерения не хватает и я дописал составление батча. но с лейблом и рамкой так же проблемы.

приложу блокнот: https://www.kaggle.com/alihanurumov/detection

def gen_data(id_from, id_to):
    x = 0
    while x == 0:
        image = []
        features = []
        label = []
        k = 0
        for i in range(batch_size):
            i = random.randint(id_from, id_to)
            feat = augmented_images_df.x_min[i], augmented_images_df.y_min[i], augmented_images_df.x_max[i], augmented_images_df.y_max[i]
            lab = augmented_images_df['class'][i]
            img = cv2.imread(augmented_images_df.filename[i])
            img = cv2.resize(img, (image_size, image_size))
            image.append(np.array(img))
            features.append(np.array(feat))
            label.append(np.array(lab))

        
    
    yield np.array(image), {"box_output": features, "class_output":  label}   #   [np.array(features), np.array(label)]

generator_train = gen_data(0, int(augmented_images_df.shape[0] * 0.85)) generator_valid = gen_data(int(augmented_images_df.shape[0] * 0.85), augmented_images_df.shape[0])

А это сама сеть

base_model = tf.keras.applications.NASNetMobile( input_tensor = Input(shape = (image_size, 
image_size, 3)), include_top = False, weights = 'imagenet')
base_model.trainable = False
base_model_output = base_model.output
flattened_output = GlobalAveragePooling2D()(base_model_output)
layer = Dense(256, activation = "relu")(flattened_output)
layer = Dense(128, activation = "relu")(layer)
layer = Dropout(0.2)(layer)
layer = Dense(64, activation = "relu")(layer)
layer = Dropout(0.2)(layer )
layer = Dense(32, activation = "relu")(layer)
layer_predictions = Dense(3, activation = 'softmax',name = "class_output")(layer)
box_output = Dense(256, activation = "relu")(flattened_output)
box_output = Dense(128, activation = "relu")(box_output)
box_output = Dropout(0.2)(box_output )
box_output = Dense(64, activation = "relu")(box_output)
box_output = Dropout(0.2)(box_output )
box_output = Dense(32, activation = "relu")(box_output)

box_predictions = Dense(4, activation = 'sigmoid', name= "box_output")(box_output)

model = Model(inputs = base_model.input, outputs = [box_predictions, layer_predictions])  
losses = {'box_output': 'mean_squared_error', 'class_output': 'categorical_crossentropy'}
loss_weights = {"box_output": 1.0, "class_output": 1.0}
metrics = {'box_output': 'mse', 'class_output': 'accuracy'}
stop = EarlyStopping(monitor = "val_loss", min_delta = 0.0001, patience = 40, restore_best_weights = True)
reduce_lr = ReduceLROnPlateau(monitor = "val_loss", factor = 0.0002, patience = 30, min_lr = 1e-7, verbose = 1)
opt = SGD(lr = 1e-3, momentum = 0.9)
model.compile(optimizer = opt, loss = losses, loss_weights = loss_weights, metrics = metrics)


history = model.fit(generator_train, validation_data = generator_valid, batch_size = 32, epochs = 500,
                callbacks = [reduce_lr, stop])

Ответы (1 шт):

Автор решения: Alihan Urumov
def gen_data(data, id_from, id_to):

    n = 0
    len_n = int((id_to - id_from) // (batch_size + 1)) * (batch_size + 1)

    while True:
        image = np.zeros((batch_size, image_size, image_size, 3), dtype='float32')
        features = np.zeros((batch_size, 4), dtype='float32')
        label = np.zeros((batch_size, 1), dtype='float32')
        for i in range(batch_size):            
            feat = data.x_min[n], data.y_min[n], data.x_max[n], data.y_max[n]
            lab = data['class'][n]
            img = cv2.imread(data.filename[n])
            img = cv2.resize(img, (image_size, image_size))
            img = img/255.
            image[i, :, :, :] = img
            features[i, ] = feat
            label[i, ] = lab
            if n != len_n:
                n += 1
            else:
                n = 0
    
        yield (np.array(image), {"box_output": features, "class_output":  label})
→ Ссылка