小编LI *_*ong的帖子

tf.image.resize_bilinear vs cv2.resize

结果tf.image.resize_bilinear与之完全不同cv2.resize.

我发现这有点麻烦.设置align_corners=True并不总是合理的,因为四个角并不总是固定在角落里.那么无论如何要让它更"对称"吗?

代码重现:

import tensorflow as tf
import numpy as np
import cv2
np.set_printoptions(precision=3)
resize_shape = (10, 10)

a = np.ones((1, 2, 2, 1), dtype=np.float32)
a[0, 0, 0, 0] = 5.0
a[0, 1, 1, 0] = 5.0

b = tf.constant(a, dtype=tf.float32)
c = tf.image.resize_bilinear(b, resize_shape)

with tf.Session() as sess:
    np_c = sess.run(c)
    print np_c[0, :, :, 0]

print cv2.resize(a[0], resize_shape, interpolation=cv2.INTER_LINEAR)
Run Code Online (Sandbox Code Playgroud)

获得的结果:

# tf.image.resize_bilinear
[[ 5.    4.2   3.4   2.6   1.8   1.    1.    1.    1. …
Run Code Online (Sandbox Code Playgroud)

opencv image-resizing tensorflow bilinear-interpolation

12
推荐指数
1
解决办法
4201
查看次数

使用同步手段和变量来实现多GPU BN层的方法

我想知道在使用多GPU进行训练时,通过同步批量统计来实现批量规范化层的可能方法.

Caffe也许有一些caffe可以做的变种,比如链接.但是对于BN层,我的理解是它仍然只同步层的输出,而不是平均值和变量.也许MPI可以同步手段和变量,但我认为MPI有点难以实现.

火炬我在这里这里看到了一些评论,它们显示了running_mean和running_var可以同步,但我认为批量平均值和批量变量不能或难以同步.

Tensorflow通常,它与caffe和torch相同.BN的实施是指这一点.我知道tensorflow可以将操作分配给指定的任何设备tf.device().但是平均值和变量的计算是在BN层的中间,所以如果我在cpu中收集平均值和变量,我的代码将是这样的:

cpu_gather = []
label_batches = []
for i in range(num_gpu):
    with tf.device('/gpu:%d' % i):
        with tf.variable_scope('block1', reuse=i > 0):
            image_batch, label_batch = cifar_input.build_input('cifar10', train_data_path, batch_size, 'train')
            label_batches.append(label_batch)

            x = _conv('weights', image_batch, 3, 3, 16, _stride_arr(1))
            block1_gather.append(x)

with tf.device('/cpu:0'):
    print block1_gather[0].get_shape()
    x1 = tf.concat(block1_gather, 0)
    # print x1.get_shape()
    mean, variance = tf.nn.moments(x1, [0, 1, 2], name='moments')

for i in range(num_gpu):
    with tf.device('/gpu:%d' % i): …
Run Code Online (Sandbox Code Playgroud)

multi-gpu torch caffe tensorflow batch-normalization

11
推荐指数
1
解决办法
1817
查看次数

为什么我的代码比opencv慢得多,因为简单的StereoBM算法呢?

这是我用于实现简单testBM算法的测试代码,没有预过滤.但是当窗口大小较大时需要大约400毫秒甚至更长时间,而opencv(CPU不是GPU)的StereoBM需要20毫秒.我检查了StereoBM的来源,但我很难理解它.有谁知道为什么?

以下是我的代码.

void testBM(const Mat &left0, 
            const Mat &right0, 
            Mat &disparity, 
            int SAD, 
            int searchRange)
{
    int cols = left0.cols;
    int rows = left0.rows;
    int total = cols*rows;
    const uchar* data_left = left0.ptr<uchar>(0);
    const uchar* data_right = right0.ptr<uchar>(0);
    uchar* data_dm = new uchar[total];
    int dbNum = 2 * SAD + 1;
    int dNum = dbNum * dbNum;
    //x is col index in the dbNum * dbNum window
    //y is row index in this window
    //z is (x + y * …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm opencv stereo-3d

8
推荐指数
1
解决办法
972
查看次数