def _deconvolution(graph, sess, op_tensor, X, feed_dict):
out = []
with graph.as_default() as g:
# get shape of tensor
tensor_shape = op_tensor.get_shape().as_list()
with sess.as_default() as sess:
# creating placeholders to pass featuremaps and
# creating gradient ops
featuremap = [tf.placeholder(tf.int32) for i in range(config["N"])]
reconstruct = [tf.gradients(tf.transpose(tf.transpose(op_tensor)[featuremap[i]]), X)[0] for i in range(config["N"])]
# Execute the gradient operations in batches of 'n'
for i in range(0, tensor_shape[-1], config["N"]):
c = 0
for j in range(config["N"]):
if (i + j) < tensor_shape[-1]:
feed_dict[featuremap[j]] = i + j
c += 1
if c > 0:
out.extend(sess.run(reconstruct[:c], feed_dict = feed_dict))
return out
评论列表
文章目录