TimeSeriesGenerator属于`steps_per_epoch` /`steps` ValueError

时间:2019-12-04 14:43:13

标签: tensorflow keras time-series

我有一个带有多个输入的tensorflow.keras模型,其中一个是时间序列数据。我已经为输入创建了生成器函数:

def ts_generator(cat_var_inputs, x_input, y_input, ts_length, batch_size=256):
    inputs = []
    for cat_var_input in cat_var_inputs:
        data_gen = TimeseriesGenerator(data=cat_var_input, 
                                       targets=y_input, 
                                       length=1,
                                       batch_size=batch_size)
        inputs.append(data_gen[0])

    data_gen = TimeseriesGenerator(data=x_input, 
                                   targets=y_input, 
                                   length=ts_length,
                                   batch_size=batch_size)
    inputs.append(data_gen[0])

    return inputs, data_gen[1]

我正在尝试将其用于model.fit_generation

generator = ts_generator([cond_Niche_input, 
                          cond_AuthorForTitle_input, 
                          cond_Seria_input], 
                          x_input_train, 
                          y_input_train, 
                          TIME_STEPS)
model.fit_generator(generator, steps_per_epoch=np.ceil(NUM_SAMPLES//256), epochs=400, verbose=1)

但是它因错误而掉线了:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-ad24f9e9eb03> in <module>()
      5                          y_input_train,
      6                          TIME_STEPS)
----> 7 model.fit_generator(generator, steps_per_epoch=np.ceil(NUM_SAMPLES//256), epochs=400, verbose=1)
      8 
      9 #fit(x=[cond_Niche_input, cond_AuthorForTitle_input, cond_Seria_input, x_input_train],

~\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   1301         shuffle=shuffle,
   1302         initial_epoch=initial_epoch,
-> 1303         steps_name='steps_per_epoch')
   1304 
   1305   def evaluate_generator(self,

~\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\keras\engine\training_generator.py in model_iteration(model, data, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch, mode, batch_size, steps_name, **kwargs)
    142       batch_size=batch_size,
    143       epochs=epochs - initial_epoch,
--> 144       shuffle=shuffle)
    145 
    146   do_validation = validation_data is not None

~\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\keras\engine\training_generator.py in convert_to_generator_like(data, batch_size, steps_per_epoch, epochs, shuffle)
    478   if batch_size is None:
    479     raise ValueError(
--> 480         'When passing input data as arrays, do not specify '
    481         '`steps_per_epoch`/`steps` argument. Please use `batch_size` instead.')
    482   steps_per_epoch = int(math.ceil(num_samples / batch_size))

ValueError: When passing input data as arrays, do not specify `steps_per_epoch`/`steps` argument. Please use `batch_size` instead.

有人可以请我解释一下出什么事了吗

0 个答案:

没有答案