def model(X, Y, k1, k2, paras, flag='single'):
assert(flag=='single' or flag=='combine')
X = tf.reshape(X, shape=[-1, boxheight, boxwidth, 1])
yreshape = tf.reshape(Y, [-1, boxheight, boxwidth, 1])
yonehot = tf.concat(3, [1-yreshape, yreshape])
if flag == 'combine':
hconv4clip = buildcombmodel(X, paras, fusion=False)
#h1, h2, h3, h4 = tf.split(3, 4, hconv4clip)
q_train, q_test = crfrnn(hconv4clip, paras['wsmooth'], paras['wcontra'], k1, k2,
trainiter=5, testiter=10, wunary=paras['wunary'])
else:
hconv4clip = buildmodel(X, paras)
q_train, q_test = crfrnn(hconv4clip, paras['wsmooth'], paras['wcontra'], k1, k2,
trainiter=5, testiter=10)
#hconv4log = -tf.log(hconv4clip)
#q_train = tf.reshape(q_train, [-1, boxheight, boxwidth, 2])
#q_train = -tf.log(hconv4clip)
q_trainclip = tf.clip_by_value(q_train, 1e-6, 1.)
trainenergy = tf.reduce_sum(-tf.log(q_trainclip)*yonehot, reduction_indices=3)
#trainenergy = tf.reduce_prod(trainenergy, reduction_indices=[1,2])
trainenergy = tf.reduce_mean(trainenergy, [0,1,2])
#q_test = hconv4clip
#q_test = crfrnn(hconv4, paras['wsmooth'], paras['wcontra'], k1, k2, iter=5)
q_test = tf.reshape(q_test, [-1, boxheight, boxwidth, 2])
testenergy = tf.reduce_sum(tf.mul(q_test, yonehot), reduction_indices=3)
#testenergy = tf.reduce_prod(testenergy, reduction_indices=[1,2])
testenergy = tf.reduce_mean(testenergy, [0,1,2])
predarg = tf.argmax(q_test, 3)
yint64 = tf.to_int64(Y)
acc = tf.equal(yint64, predarg)
acc = tf.to_float(acc)
accuracy = tf.reduce_mean(acc, [0,1,2])
di = dice_tf(tf.reshape(yint64, [-1,]), tf.reshape(predarg, [-1,]))
return trainenergy, accuracy, di, testenergy, predarg
utils.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录