我正在尝试为TensorArray和while_loop组合生成一个非常简单的示例:
# 1000 sequence in the length of 100
matrix = tf.placeholder(tf.int32, shape=(100, 1000), name="input_matrix")
matrix_rows = tf.shape(matrix)[0]
ta = tf.TensorArray(tf.float32, size=matrix_rows)
ta = ta.unstack(matrix)
init_state = (0, ta)
condition = lambda i, _: i < n
body = lambda i, ta: (i + 1, ta.write(i,ta.read(i)*2))
# run the graph
with tf.Session() as sess:
(n, ta_final) = sess.run(tf.while_loop(condition, body, init_state),feed_dict={matrix: tf.ones(tf.float32, shape=(100,1000))})
print (ta_final.stack())
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
ValueError: Tensor("while/LoopCond:0", shape=(), dtype=bool) must be from the same graph as Tensor("Merge:0", shape=(), dtype=float32).
Run Code Online (Sandbox Code Playgroud)
任何人都知道问题是什么?
我的理解正确吗,以下代码中“ greed_search.fit(X,Y)”与嵌套的CV没有任何关系?这意味着无法使用sklearn中的嵌套CV获得最佳参数。
# inner cross_validation
greed_search = GridSearchCV(estimator=estimator, param_grid=parameters, cv=inner_cv, scoring=optimized_for)
greed_search.fit(X, optimization_label)
# Nested CV with parameter optimization
nested_score = cross_val_score(greed_search, X=X, y=Y, cv=outer_cv)
Run Code Online (Sandbox Code Playgroud) classification machine-learning scikit-learn cross-validation