UnboundLocalError:分配前引用了局部变量“batch_outputs”

use*_*134 10 python machine-learning keras

我正在使用 Keras 编写机器学习代码来对前列腺癌的严重程度进行分级。运行后出现如下错误:

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-14-0e08590512ec> in <module>
      8     for file in column:
      9         data = generate_tiles(file)
---> 10         prediction = model.predict(data)
     11         max_score = prediction.max()
     12 

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
     86       raise ValueError('{} is not supported in multi-worker mode.'.format(
     87           method.__name__))
---> 88     return method(self, *args, **kwargs)
     89 
     90   return tf_decorator.make_decorator(

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
   1283             callbacks.on_predict_batch_end(step, {'outputs': batch_outputs})
   1284       callbacks.on_predict_end()
-> 1285     all_outputs = nest.map_structure_up_to(batch_outputs, concat, outputs)
   1286     return tf_utils.to_numpy_or_python_type(all_outputs)
   1287 

UnboundLocalError: local variable 'batch_outputs' referenced before assignment
Run Code Online (Sandbox Code Playgroud)

有谁知道批处理输出也指的是什么?我的代码中没有这样的变量。

Gau*_*nga 16

当您将空数组传递给 Keras 时,通常会抛出此错误。检查您正在传递的数组。

  • 为什么它不直接说明您传递了一个空数组? (5认同)