在tensorflow调试器中使用run -t <T>
命令时,它会失败,并出现一些None
值错误。
以下代码来自示例模型Keras文档。使用run -f has_inf_or_nan
在tensorflow调试器中运行良好:
import tensorflow.keras as keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation
from tensorflow.keras.optimizers import SGD
# Generate dummy data
import numpy as np
import sys
import tensorflow as tf
if '--debug' in sys.argv:
from tensorflow.python import debug as tf_debug
tf.keras.backend.set_session(tf_debug.LocalCLIDebugWrapperSession(tf.Session()))
print('debug mode')
x_train = np.random.random((1000, 20))
y_train = keras.utils.to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10)
x_test = np.random.random((100, 20))
y_test = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)
model = Sequential()
# Dense(64) is a fully-connected layer with 64 hidden units.
# in the first layer, you must specify the expected input data shape:
# here, 20-dimensional vectors.
model.add(Dense(64, activation='relu', input_dim=20))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
optimizer=sgd,
metrics=['accuracy'])
model.fit(x_train, y_train,
epochs=20,
batch_size=128)
但是,在使用run -t 100
命令时失败:
$ python3 /tmp/keras_debug.py --debug
2019-06-04 16:15:04.900460: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
debug mode
WARNING:tensorflow:From /Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in $
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From /Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/keras/layers/core.py:143: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be remov$
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
WARNING:tensorflow:From /Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Epoch 1/20
Traceback (most recent call last):
File "/tmp/keras_debug.py", line 38, in <module>
batch_size=128)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 880, in fit
validation_steps=validation_steps)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/keras/engine/training_arrays.py", line 329, in model_iteration
batch_outs = f(ins_batch)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/keras/backend.py", line 3076, in __call__
run_metadata=self.run_metadata)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/debug/wrappers/framework.py", line 648, in wrapped_runner
callable_runner_args=feed_values)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/debug/wrappers/framework.py", line 589, in run
run_metadata=run_metadata)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 929, in run
run_metadata_ptr)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1137, in _run
self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 471, in __init__
self._fetch_mapper = _FetchMapper.for_fetch(fetches)
File "/Users/me/.virtualenv/dev/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 258, in for_fetch
type(fetch)))
TypeError: Fetch argument None has invalid type <class 'NoneType'>
解决方法或解决方法是什么?