在R中我有一个带有预测方法的R6类。当调用预测方法时,它应该运行张量流计算,这里乘以输入和权重。
这是代码:
NeuralNetworkTensorflow = R6::R6Class("NeuralNetworkTensorflow",
public = list(
inputs = NULL,
weights = NULL,
Q = NULL,
sess = NULL,
initialize = function() {
tf$reset_default_graph()
self$inputs = tf$placeholder(tf$float32, shape(1L, 5L))
self$weights = tf$Variable(tf$random_uniform(shape(5L, 4L), 0, 0.01))
self$Q = tf$matmul(self$inputs, self$weights)
self$sess = tf$Session()
self$sess$run(tf$global_variables_initializer())
},
predict = function(inputs) {
self$sess$run(self$Q, feed_dict = dict(inputs = inputs))
}
)
)
my_nn = NeuralNetworkTensorflow$new()
my_nn$predict(matrix(c(0, 1, 0, 0, 1), ncol = 5))
它返回以下错误:
Error in py_call_impl(callable, dots$args, dots$keywords) :
SystemError: <built-in function TF_NewBuffer> returned a result with an error set
我不确定,这里出了什么问题。有人可以帮忙吗?