keras-arcface: How to solve this problem?

Traceback (most recent call last):
  File "train_liveness.py", line 142, in <module>
    epochs=EPOCHS)
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\engine\training.py", line 1418, in fit_generator
    initial_epoch=initial_epoch)
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\engine\training_generator.py", line 144, in fit_generator
    val_x, val_y, val_sample_weight)
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\engine\training.py", line 751, in _standardize_user_data
    exception_prefix='input')
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\engine\training_utils.py", line 128, in standardize_input_data
    'with shape ' + str(data_shape))
ValueError: Error when checking input: expected input_2 to have 2 dimensions, but got array with shape (78, 2, 2)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

It’s because that labels are one-hot encoded twice. Please try to remove following line:

labels = np_utils.to_categorical(labels, 2)

ImageDataGenerator doesn’t support the tuple ([X_train, y_train], y_train)… Please try following code:

class MyImageDataGenerator:
    def __init__(self):
        self.datagen = ImageDataGenerator(rotation_range=20, zoom_range=0.15, brightness_range=[0.5, 1.5],
                         width_shift_range=0.2, height_shift_range=0.2,
                         shear_range=0.15, horizontal_flip=True, fill_mode="nearest")

    def flow(self, x, y=None, batch_size=32, shuffle=True, sample_weight=None,
             seed=None, save_to_dir=None, save_prefix='', save_format='png', subset=None):
        batches = self.datagen.flow(x, y, batch_size, shuffle, sample_weight,
                               seed, save_to_dir, save_prefix, save_format, subset)

        while True:
            x_batch, y_batch = next(batches)

            yield [x_batch, y_batch], y_batch

aug = MyImageDataGenerator()


H = model.fit_generator(aug.flow(trainX, trainY, batch_size=BS),
                        validation_data=([testX, testY], testY), steps_per_epoch=len(trainX) // BS,
                        epochs=EPOCHS)

Did you pass the tuple (X_train, y_train) to the generator? That is not right. You must pass the tuple ([X_train, y_train], y_train) to the generator.

Hi! Please paste your train_liveness.py here.