ValueError: Op type not registered 'FertileStatsResourceHandleOp' in binary

宁静致远 提问于 4个月前

代码:

from __future__ import print_function

# Ignore all GPUs, tf random forest does not benefit from it.
import os

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

os.environ["CUDA_VISIBLE_DEVICES"] = ""

# Import MNIST data
from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data.read_data_sets("./tmp/data/", one_hot=False)

# Parameters
num_steps = 500  # Total steps to train
batch_size = 1024  # The number of samples per batch
num_classes = 10  # The 10 digits
num_features = 784  # Each image is 28x28 pixels
num_trees = 10
max_nodes = 1000

# 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 = mnist.train.next_batch(batch_size)
    _, 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 = mnist.test.images, mnist.test.labels
print("Test Accuracy:", sess.run(accuracy_op, feed_dict={X: test_x, Y: test_y}))


报错:

Traceback (most recent call last):
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1589, in _create_c_op
    c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Op type not registered 'FertileStatsResourceHandleOp' in binary running on ZHUJINGXIONG-PC. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) `tf.contrib.resampler` should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed. while building NodeDef 'stats-0'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\_pydev_bundle\pydev_umd.py", line 194, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/ZhuJingxiong/Desktop/HiPython/h.py", line 45, in <module>
    forest_graph = tensor_forest.RandomForestGraphs(hparams)
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\tensor_forest\python\tensor_forest.py", line 386, in __init__
    tree_configs=tree_configs, tree_stats=tree_stats)
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\tensor_forest\python\tensor_forest.py", line 357, in __init__
    params, i, training, **kwargs))
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\tensor_forest\python\tensor_forest.py", line 318, in __init__
    params, tree_stat, self.get_tree_name('stats', tree_num))
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\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:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\tensor_forest\python\ops\gen_stats_ops.py", line 223, in fertile_stats_resource_handle_op
    shared_name=shared_name, name=name)
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3414, in create_op
    op_def=op_def)
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1756, in __init__
    control_input_ops)
  File "C:\Users\ZhuJingxiong\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1592, in _create_c_op
    raise ValueError(str(e))
ValueError: Op type not registered 'FertileStatsResourceHandleOp' in binary running on ZHUJINGXIONG-PC. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) `tf.contrib.resampler` should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed. while building NodeDef 'stats-0'


一波未平一波又起的问题,那题仁兄帮忙看下?谢了!

回答 1
1 个回答

import tensorflow.contrib

回复 · 1
宁静致远 回复 Ξ魂牵梦萦Ξ 4个月前 回复
还是不行哦。
需要登录后才能回答,快点击 来分享你的回答吧~
1 关注
0 收藏,293 浏览
邀请回答
分享到