与循环处理不一致

时间:2019-04-10 23:31:40

标签: python tensorflow google-compute-engine tensorflow-estimator tpu

我正在尝试评估模型的准确性。我正在计算每个类别的logit之间的平均成对欧几里得相似度的平均值。我正在使用TPUEstimator训练网络。

我在google Colab中有测试代码,它可以正常工作,但在实际的VM机器上却不能。

它们都使用Tensorflow 1.13.1。

Colab运行的Python 2.7.15rc1,其中VM具有2.7.13。

labels_count = tf.size(tf.unique(labels)[0])
hot = tf.one_hot(labels, labels_count, dtype=tf.int32)

accu = []
for i in range(0, hot.shape[1]):
  a = tf.dynamic_partition(logits, hot[:, i],2)[1]
  out = pairwise_distance(a)
  accu.append(out)
accus = tf.convert_to_tensor(accu)
mean = tf.reduce_mean(tf.boolean_mask(accus, tf.logical_not(tf.is_nan(accus))))

代码在TypeError: __int__ should return int object上在VM上出错,但是在Colab中可以正常工作,但不知道可能是什么问题?


编辑:好的,在Colab中转载了该问题。在Colab中,我使用的tf.constant在实际代码中未使用。那么在这种情况下如何使范围正常工作?

0 个答案:

没有答案