我正在尝试运行神经网络算法,但出现错误“ ValueError:生成器已在执行”。我读过我可以通过使worker = 1来解决此问题,但这没有帮助。
我已经看过this post,但不确定如何实现它,或者我是否有必要。我也尝试设置use_multiprocessing = True,但这给出了另一个错误。我已经附上了我认为相关的Python代码和完整的错误代码。在Anaconda / Spyder中从2.2.4降级后,我正在使用Keras 2.0.8。
import os
os.environ["CUDA_VISIBLE_DEVICES"] = ""
from keras.optimizers import Adam
from keras.callbacks import EarlyStopping, TensorBoard, ModelCheckpoint, ReduceLROnPlateau
import matplotlib.pyplot as plt
from DataGenerator import generator
import datetime #, os
import models
import numpy as np
from metrics import metrics_callback, weighted_categorical_crossentropy
from multiprocessing import Pool
batch_size = 16
n_epochs = 150
windowsize = 1024
data_gen = generator(folder=datafolder, batch_size=batch_size, windowsize=windowsize)
train_gen,train_batches = data_gen.train_gen_online()
test_gen,test_batches = data_gen.test_gen()
train_gen=train_gen()
test_gen=test_gen()
.....
##ERROR HAPPENS ON LINE BELOW
model.fit_generator(generator=train_gen,
steps_per_epoch=train_batches,
epochs=1,
validation_data=train_gen,
validation_steps = 100,
max_queue_size=40,
workers=1,
use_multiprocessing=False
)
test_x, test_y = next(test_gen)
test_pred = model.predict(test_x)
由于没有多重处理的事实,我希望代码能够运行并提供神经网络作为输出,尽管非常慢。
Epoch 1/1
10/11 [==========================>...] - ETA: 42s - loss: 6246.2208 - mean_squared_error: 6246.2208 Exception in thread Thread-8:
Traceback (most recent call last):
File "C:\Users\s164286\AppData\Local\Continuum\anaconda3\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\s164286\AppData\Local\Continuum\anaconda3\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\s164286\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\utils\data_utils.py", line 568, in data_generator_task
generator_output = next(self._generator)
ValueError: generator already executing