tensorflow.python.framework.errors_impl.NotFoundError:操作类型未注册' FertileStatsResourceHandleOp'

时间:2017-12-20 08:01:08

标签: python tensorflow

我试图为tensorflow运行一些例子但是因为这样的异常它不起作用。我不知道如何解决它?

我可能需要安装一些软件包,或者此示例与Tensorflow 1.4不兼容。我使用的是Windows 10,没有cuda,Python 3.6。

是否需要其他版本的Tensorflow或Windows 10不支持?

Traceback (most recent call last):
  File "C:/Users/Cezary Wagner/PycharmProjects/tf-xor/src/s02_forest_xor.py", line 32, in <module>
    forest_graph = tensor_forest.RandomForestGraphs(hparams)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\contrib\tensor_forest\python\tensor_forest.py", line 376, in __init__
    tree_variables_class=tree_variables_class)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\contrib\tensor_forest\python\tensor_forest.py", line 350, in __init__
    self.variables.append(tree_variables_class(params, i, training))
  File "C:\root\Python36-64\lib\site-packages\tensorflow\contrib\tensor_forest\python\tensor_forest.py", line 318, in __init__
    params, '', self.get_tree_name('stats', tree_num))
  File "C:\root\Python36-64\lib\site-packages\tensorflow\contrib\tensor_forest\python\ops\stats_ops.py", line 102, in fertile_stats_variable
    container, shared_name=name, name=name)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\contrib\tensor_forest\python\ops\gen_stats_ops.py", line 134, in fertile_stats_resource_handle_op
    shared_name=shared_name, name=name)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\python\framework\ops.py", line 2958, in create_op
    set_shapes_for_outputs(ret)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\python\framework\ops.py", line 2209, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\python\framework\ops.py", line 2159, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 627, in call_cpp_shape_fn
    require_shape_fn)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 686, in _call_cpp_shape_fn_impl
    input_tensors_as_shapes, status)
  File "C:\root\Python36-64\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 473, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: Op type not registered 'FertileStatsResourceHandleOp' in binary running on TERMIT. Make sure the Op and Kernel are registered in the binary running in this process.

Process finished with exit code 1

停止:

# Random Forest Parameters
hparams = tensor_forest.ForestHParams(num_classes=num_classes,
                                      num_features=num_features,
                                      num_trees=num_trees,
                                      max_nodes=max_nodes).fill()

完整的程序代码:

import tensorflow as tf
from tensorflow.contrib.tensor_forest.python import tensor_forest
from tensorflow.python.ops import resources


# Parameters
num_steps = 500 # Total steps to train
num_classes = 2 # The 10 digits
num_features = 2 # Each image is 28x28 pixels
num_trees = 10
max_nodes = 1000

io = (
    ((0, 0), (0,)),
    ((0, 1), (1,)),
    ((1, 0), (1,)),
    ((1, 1), (0,)),
)

# Input and Target data
X = tf.placeholder(tf.float32, shape=[None, num_features])
# For random forest, labels must be integers (the class id)
Y = tf.placeholder(tf.int32, shape=[None])

# Random Forest Parameters
hparams = tensor_forest.ForestHParams(num_classes=num_classes,
                                      num_features=num_features,
                                      num_trees=num_trees,
                                      max_nodes=max_nodes).fill()

# Build the Random Forest
forest_graph = tensor_forest.RandomForestGraphs(hparams)
# Get training graph and loss
train_op = forest_graph.training_graph(X, Y)
loss_op = forest_graph.training_loss(X, Y)

# Measure the accuracy
infer_op, _, _ = forest_graph.inference_graph(X)
correct_prediction = tf.equal(tf.argmax(infer_op, 1), tf.cast(Y, tf.int64))
accuracy_op = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

# Initialize the variables (i.e. assign their default value) and forest resources
init_vars = tf.group(tf.global_variables_initializer(),
    resources.initialize_resources(resources.shared_resources()))

# Start TensorFlow session
sess = tf.Session()

# Run the initializer
sess.run(init_vars)

# Training
for i in range(1, num_steps + 1):
    # Prepare Data
    # Get the next batch of MNIST data (only images are needed, not labels)
    batch_x, batch_y = [x[0] for x in io], [x[1] for x in io]
    _, l = sess.run([train_op, loss_op], feed_dict={X: batch_x, Y: batch_y})
    if i % 50 == 0 or i == 1:
        acc = sess.run(accuracy_op, feed_dict={X: batch_x, Y: batch_y})
        print('Step %i, Loss: %f, Acc: %f' % (i, l, acc))

# Test Model
test_x, test_y = [x[0] for x in io], [x[1] for x in io]
print("Test Accuracy:", sess.run(accuracy_op, feed_dict={X: test_x, Y: test_y}))

1 个答案:

答案 0 :(得分:0)

我今天遇到了同样的问题。 我通过更新已安装的Tensorflow(或Tensorflow-GPU)版本解决了该问题 就我而言,我使用的是1.8版本,并将其更新为1.9版。

除了所有内容之外,请检查您的Tensorflow版本并根据需要进行调整 史蒂夫