Tensorflow 1.4,python3.5,window7(64) 从https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/random_forest.py运行tensor-forest代码时, 我遇到了
的问题tensorflow.python.framework.errors_impl.NotFoundError:操作类型未在NS80011718上运行的二进制文件中注册了“FertileStatsResourceHandleOp”。确保操作和内核已在此过程中运行的二进制文件中注册。
代码:
from __future__ import print_function
import tensorflow as tf
from tensorflow.contrib.tensor_forest.python import tensor_forest
from tensorflow.python.ops import resources
# Ignore all GPUs, tf random forest does not benefit from it.
import os
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/Administrator/Desktop/het-health-ming/sleep_stage/py3/sleep_stage_classifcation/test.py", line 35, in <module>
forest_graph = tensor_forest.RandomForestGraphs(hparams)
File "D:\Anaconda2\envs\py3\lib\site-packages\tensorflow\contrib\tensor_forest\python\tensor_forest.py", line 376, in __init__
tree_variables_class=tree_variables_class)
File "D:\Anaconda2\envs\py3\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 "D:\Anaconda2\envs\py3\lib\site-packages\tensorflow\contrib\tensor_forest\python\tensor_forest.py", line 318, in __init__
params, '', self.get_tree_name('stats', tree_num))
File "D:\Anaconda2\envs\py3\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 "D:\Anaconda2\envs\py3\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 "D:\Anaconda2\envs\py3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "D:\Anaconda2\envs\py3\lib\site-packages\tensorflow\python\framework\ops.py", line 2958, in create_op
set_shapes_for_outputs(ret)
File "D:\Anaconda2\envs\py3\lib\site-packages\tensorflow\python\framework\ops.py", line 2209, in set_shapes_for_outputs
shapes = shape_func(op)
File "D:\Anaconda2\envs\py3\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 "D:\Anaconda2\envs\py3\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 627, in call_cpp_shape_fn
require_shape_fn)
File "D:\Anaconda2\envs\py3\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 686, in _call_cpp_shape_fn_impl
input_tensors_as_shapes, status)
File "D:\Anaconda2\envs\py3\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 NS80011718. Make sure the Op and Kernel are registered in the binary running in this process.
Process finished with exit code 1
有什么建议吗?
答案 0 :(得分:0)
我尝试了python 2.7 / 3.5和tensorflow 1.4 / 1.5的多个版本组合,但我无法解决它。 最后,我使用“sklearn.ensemble import RandomForestClassifier”重新实现了我的解决方案。