在tensorflow2.1中运行下面的代码汇报错误
错误为
Traceback (most recent call last):
File "E:/Python_test/SSVEP/test.py", line 528, in
callbacks=callback_lists) # verbose=2,
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\keras\engine\training.py", line 1732, in fit_generator
initial_epoch=initial_epoch)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\keras\engine\training_generator.py", line 42, in fit_generator
model._make_train_function()
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\keras\engine\training.py", line 316, in _make_train_function
loss=self.total_loss)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\keras\backend\tensorflow_backend.py", line 75, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\keras\optimizers.py", line 505, in get_updates
self.updates = [K.update_add(self.iterations, 1)]
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\keras\backend\tensorflow_backend.py", line 1268, in update_add
return tf_state_ops.assign_add(x, increment)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\ops\state_ops.py", line 195, in assign_add
return ref.assign_add(value)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 786, in assign_add
name=name)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\ops\gen_resource_variable_ops.py", line 56, in assign_add_variable_op
"AssignAddVariableOp", resource=resource, value=value, name=name)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\framework\op_def_library.py", line 468, in _apply_op_helper
preferred_dtype=default_dtype)
File "F:\ProgramData\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\framework\ops.py", line 1280, in convert_to_tensor
raise RuntimeError("Attempting to capture an EagerTensor without "
RuntimeError: Attempting to capture an EagerTensor without building a function.
将其修改如下后解决:
hist = model.fit_generator(train_data_gen, steps_per_epoch=train_data_num // batch_size, epochs=40, verbose=2,
validation_data=val_data_gen, validation_steps=val_data_num // batch_size,
callbacks=callback_lists) # verbose=2,