Tensorflow 从张量流估计器获得层激活

Tensorflow 从张量流估计器获得层激活,tensorflow,Tensorflow,我有一个神经网络张量流估计器,我称之为分类器,我想打印出网络中一个叫做pool5的层的激活 在model函数中,我调用: if mode == tf.estimator.ModeKeys.PREDICT: predictions = {"last_layer": pool5} return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions) 然后在主脚本中,我有 predictions = classif

我有一个神经网络张量流估计器,我称之为分类器,我想打印出网络中一个叫做pool5的层的激活

在model函数中,我调用:

if mode == tf.estimator.ModeKeys.PREDICT:
    predictions = {"last_layer": pool5}
    return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)
然后在主脚本中,我有

predictions = classifier.predict(input_fn=input_fn)
print(predictions["last_layer"])
但我得到的错误是

Traceback (most recent call last):
  File "C:/Users/John/AppData/Local/Programs/Python/Python35/Scripts/Estimator_5minutes.py", line 177, in <module>
    tf.app.run()
  File "C:\Users\John\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\platform\app.py", line 124, in run
    _sys.exit(main(argv))
  File "C:/Users/John/AppData/Local/Programs/Python/Python35/Scripts/Estimator_5minutes.py", line 152, in main
    print(predictions["last_layer"])
TypeError: 'generator' object is not subscriptable

这可能不是一个完美的答案,但以下是我为解决这个问题所做的

predictions = list(classifier.predict(input_fn=input_fn))
scipy.io.savemat('C:/activations.mat', {"activations": predictions})