在TensorFlow中向右移动图像

利亚姆

我已经在Tensorflow(MNIST)上进行了学习,并将权重保存在.ckpt中。现在,我想在此权重上测试我的神经网络,并用相同的图像从右边和底部平移几个像素。加载权重效果很好,但是当我打印评估时,无论翻译大约是1像素还是14像素,Tensorflow始终显示相同的结果(测试为0.9630)。这是我的打印eval函数的代码:

def eval_translation(sess, eval_correct, images_pl, labels_pl, dataset):
    print('Test Data Eval:')
    for i in range(28):
        true_count = 0  # Counts the number of correct predictions.
        steps_per_epoch = dataset.num_examples // FLAGS.batch_size
        nb_exemples = steps_per_epoch * FLAGS.batch_size
        for step in xrange(steps_per_epoch):
            images_feed, labels_feed = dataset.next_batch(FLAGS.batch_size)
            feed_dict = {images_pl: translate_right(images_feed, i), labels_pl: labels_feed}
            true_count += sess.run(eval_correct, feed_dict=feed_dict)
        precision = true_count / nb_exemples
        print('Translation: %d  Num examples: %d  Num correct: %d  Precision @ 1: %0.04f' % (i, nb_exemples, true_count, precision))

这是我加载数据并打印测试结果的功能。这是我的翻译功能:

def translate_right(images, dev):
    for i in range(len(images)):
        for j in range(len(images[i])):
            images[i][j] = np.roll(images[i][j], dev)
    return images

初始化所有变量后,我将其称为学习功能:

with tf.Graph().as_default():
    # Generate placeholders for the images and labels.
    images_placeholder, labels_placeholder = placeholder_inputs(FLAGS.batch_size)

    # Build a Graph that computes predictions from the inference model.
    weights, logits = mnist.inference(images_placeholder, neurons)

    # Add to the Graph the Ops for loss calculation.
    loss = mnist.loss(logits, labels_placeholder)

    # Add to the Graph the Ops that calculate and apply gradients.
    train_op = mnist.training(loss, learning_rate)

    # Add the Op to compare the logits to the labels during evaluation.
    eval_correct = mnist.evaluation(logits, labels_placeholder)

    # Build the summary operation based on the TF collection of Summaries.
    summary_op = tf.merge_all_summaries()

    # Create a saver for writing training checkpoints.
    save = {}
    for i in range(len(weights)):
        save['weights' + str(i)] = weights[i]
    saver = tf.train.Saver(save)

    # Create a session for running Ops on the Graph.
    sess = tf.Session()
    init = tf.initialize_all_variables()
    sess.run(init)

    # load weights
    saver.restore(sess, restore_path)

    # Instantiate a SummaryWriter to output summaries and the Graph.
    summary_writer = tf.train.SummaryWriter(FLAGS.train_dir, sess.graph)

    temps_total = time.time()

    eval_translation(sess, eval_correct, images_placeholder, labels_placeholder, dataset.test)

我不知道我的代码有什么问题,以及为什么Tensorflow似乎忽略了我的图像。有人可以帮我吗?谢谢 !

奥利维尔·莫恩德罗特(Olivier Moindrot)

您的功能translate_right不起作用,因为images[i, j]它只有一个像素(如果有灰度图像,则包含1个值)。

您应该使用的说法axisnp.roll

def translate_right(images, dev):
    return np.roll(images, dev, axis=1)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在投影仪中更改图像向右移动

来自分类Dev

图像在wordpress帖子中向右移动

来自分类Dev

在汇编中向左或向右移动字符

来自分类Dev

跨度在Firefox中向右移动

来自分类Dev

在Unity中从左向右移动Windows

来自分类Dev

动画图像以向右移动到Angular中的特定位置

来自分类Dev

如何在布局中向右移动三个图像和文本?

来自分类Dev

向右移动数组

来自分类Dev

向右移动按钮

来自分类Dev

调整页面大小时图像向左或向右移动

来自分类Dev

将 matlab 上的 m*n 图像矩阵向右移动

来自分类Dev

在Drawer Navigator工具栏中向右移动图标

来自分类Dev

是否可以在列表中向左或向右移动边框底部?

来自分类Dev

如何在html中向右移动导航栏?

来自分类Dev

如何在输入字段中向右移动箭头?

来自分类Dev

HTML表格向右移动

来自分类Dev

向右移动数组元素?

来自分类Dev

敌人不断向右移动

来自分类Dev

向右移动命令输出

来自分类Dev

R向右移动值

来自分类Dev

为什么图像显示空间并向右移动,应该填补空白

来自分类Dev

自动布局:并排对齐两个按钮并在没有图像时向右移动

来自分类Dev

GParted无法向右移动扩展分区?

来自分类Dev

下拉菜单向右移动

来自分类Dev

向右移动切换按钮

来自分类Dev

Ubuntu桌面向右移动

来自分类Dev

伸缩项目没有向右移动

来自分类Dev

为什么TextView不能向右移动?

来自分类Dev

Pygame角色不会向左或向右移动