小编msh*_*hiv的帖子

TypeError:Fetch参数的类型为float32,必须是字符串或Tensor

我正在训练CNN与例中的CNN非常相似,用于图像分割.图像为1500x1500x1,标签大小相同.

在定义CNN结构之后,以及在此代码示例中启动会话:( conv_net_test.py)

with tf.Session() as sess:
sess.run(init)
summ = tf.train.SummaryWriter('/tmp/logdir/', sess.graph_def)
step = 1
print ("import data, read from read_data_sets()...")

#Data defined by me, returns a DataSet object with testing and training images and labels for segmentation problem.
data = import_data_test.read_data_sets('Dataset')

# Keep training until reach max iterations
while step * batch_size < training_iters:
    batch_x, batch_y = data.train.next_batch(batch_size)
    print ("running backprop for step %d" % step)
    batch_x = batch_x.reshape(batch_size, n_input, n_input, n_channels)
    batch_y = batch_y.reshape(batch_size, n_input, …
Run Code Online (Sandbox Code Playgroud)

python typeerror tensorflow

16
推荐指数
1
解决办法
2万
查看次数

张量流的语义分割 - 损失函数中的ValueError(稀疏 - softmax)

所以,我正在建立一个完全卷积网络(FCN),基于Marvin Teichmann的tensorflow-fcn

我的输入图像数据暂时是750x750x3 RGB图像.在通过网络运行后,我使用shape [batch_size,750,750,2]的logits进行损失计算.

这是一个二进制分类 - 我这里有两个类,[0,1]在我的标签中(形状[batch_sizex750x750].这些进入损失函数,如下:

def loss(logits, labels, num_classes):
with tf.name_scope('loss mine'):
    logits = tf.to_float(tf.reshape(logits, [-1, num_classes]))

    #CHANGE labels type to int, for sparse_softmax...
    labels = tf.to_int64(tf.reshape(labels, [-1]))

    print ('shape of logits: %s' % str(logits.get_shape()))
    print ('shape of labels: %s' % str(labels.get_shape()))

    cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels, name='Cross_Entropy')
    tf.add_to_collection('losses', cross_entropy)

    loss = tf.add_n(tf.get_collection('losses'), name='total_loss')
return loss
Run Code Online (Sandbox Code Playgroud)

这些是重塑后的logits和标签的形状:

shape of logits: (562500, 2)
shape of labels: (562500,)
Run Code Online (Sandbox Code Playgroud)

在这里,它抛出一个ValueError说明:

Shapes () and (562500,) are not compatible
Run Code Online (Sandbox Code Playgroud)

完整追溯如下:

  File "train.py", …
Run Code Online (Sandbox Code Playgroud)

python image-segmentation tensorflow softmax

6
推荐指数
1
解决办法
1448
查看次数