caffe调整图像使所有值都为0

Ars*_*tic 0 python image-processing neural-network deep-learning caffe

我在使用caffe从图像生成HDF5数据文件时遇到了这个问题.

所述caffe.io.load_image载荷图像转换成在归一化范围0-1 varible.

调整大小,但所有值都img转换为零

    img = caffe.io.load_image( patht_to_file )
    print img.shape
    print img.dtype
    img = caffe.io.resize( img, (3,SIZE, SIZE) ) #resizes but all values in img converted to zero
    print img.shape
    print img.dtype
Run Code Online (Sandbox Code Playgroud)

我得到的输出是

  (240, 320, 3) 
  float32
  (3, 58, 58) 
  float64
Run Code Online (Sandbox Code Playgroud)

img对于某些值,将值更改为全0,任何人都可以帮我修复此问题.

我想同样的float32改变resize命令的顺序给出正确的输出 给var真正的非零值,img 但顺序和类型不是我需要的

img = caffe.io.resize( img, (SIZE, SIZE, 3) ) # Gives real non zero values to var img
print img.shape
print img.dtype
Run Code Online (Sandbox Code Playgroud)

产量

(240, 320, 3) 
float32
(58, 58, 3) 
float64
Run Code Online (Sandbox Code Playgroud)

我需要将形状设置为3,58,58而不将所有值转换为零,即实际数据

Sha*_*hai 5

什么地方出了错?

img是一个三维数组,但不同的维度有不同的含义.前两个(240,320)空间维度,而第三个(3)是"通道"(或"特征")维度.当resize您想要更改空间维度的图像时,甚至混合(插入)相邻值,但您始终希望保持通道完整:您不希望混合"红色"值以决定"绿色"值用于邻近像素.

在caffe中,为了获取形状的输入图像(240,320,3)并将其转换为形状,(3,58,58)您需要做件事:
1.将空间尺寸从使用(240,320)变为(58,58)使用caffe.io.resize_image.这个阶段将导致img形状(58,58,3).
2.第二阶段是移动/ transpose尺寸,img使通道尺寸成为第一个:img.transpose((2,0,1)).

解:

# first, resize the spatial dimensions, do not touch the channels
img = caffe.io.resize_image( img, (SIZE,SIZE), interp_order=3 )
# transpose the dimensions from H-W-C to C-H-W
img = img.transpose( (2,0,1) )
Run Code Online (Sandbox Code Playgroud)

有关resize_image详细信息,请参阅

PS,
将RGB图像更改为BGR也很常见.你跳过了这个阶段.这是故意的吗?