gpt4 book ai didi

python - Keras:UnboundLocalError:分配前引用了局部变量 'logs'

转载 作者:行者123 更新时间:2023-12-03 15:21:54 25 4
gpt4 key购买 nike

我对 python 比较陌生,在尝试训练聊天机器人时,我收到了错误:‘UnboundLocalError: local variable ‘logs’ referenced before assignment‘。我使用 model.fit 来训练:

model.fit(x_train, y_train, epochs=7)

我收到了错误:
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-10-847c83704a3f> in <module>()
2 x_train,
3 y_train,
----> 4 epochs=7
5 )

1 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
64 def _method_wrapper(self, *args, **kwargs):
65 if not self._in_multi_worker_mode(): # pylint: disable=protected-access
---> 66 return method(self, *args, **kwargs)
67
68 # Running inside `run_distribute_coordinator` already.

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
854 logs = tmp_logs # No error, now safe to assign to logs.
855 callbacks.on_train_batch_end(step, logs)
--> 856 epoch_logs = copy.copy(logs)
857
858 # Run validation.

UnboundLocalError: local variable 'logs' referenced before assignment


我在 google colab 中运行了这个,链接在这里: https://colab.research.google.com/drive/18uTvvKYDrd8CQi31kg6vX2Dbxg1gD20X?usp=sharing

我在 kaggle 上使用了 chatterbot/english 数据集: https://www.kaggle.com/kausr25/chatterbotenglish

最佳答案

这个问题看起来类似于我在处理小数据集时遇到的问题,它在这个线程中进行了介绍:#38064 .
我解决了我设置较小batch_size的特定问题,在我的情况下:

batch_size = 2

关于python - Keras:UnboundLocalError:分配前引用了局部变量 'logs',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61705858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com