MXNet的ImageRecordIter和ImageRecordDataset产生不同的形状[CxHxW]与[HxWxC]

时间:2019-12-23 20:30:11

标签: python mxnet

我的数据文件是使用im2rec创建的,包含3个通道和大小(224x224)的图像。当我从该数据集创建mx.io.ImageRecordIter时,其形状显示为[3,224,224]。但是,当我创建mx.gluon.data.vision.datasets.ImageRecordDataset(直接加载我的文件)时,形状为[224,224,3]

这是否会导致VGG11 CNN的训练器因Deferred initialization failed because shape cannot be inferred. Error in operator vgg0_pool1_fwd: [22:20:57] src/operator/nn/pooling.cc:193: Check failed: param.kernel[1] <= dshape_nchw[3] + 2 * param.pad[1]: kernel size (2) exceeds input (1 padded to 1)而失败?我该如何解决?

import mxnet as mx
import numpy as np
import matplotlib.pyplot as plt
import cv2

# this works

dataiter = mx.io.ImageRecordIter(
  path_imgrec="training.bin",
  path_imglist="training.lst",
  data_shape=(3,224,224),
  batch_size=4,
  label_width=1
)

batch = dataiter.next() # first batch.
images = batch.data[0] # This will contain 4 (=batch_size) images each of 3x227x227.

print("dataiter: shape is %s " %( dataiter.next().data[0].shape, ));

dataset = mx.gluon.data.vision.datasets.ImageRecordDataset("training.bin");
print("dataset: shape is %s " %( dataset[0][0].shape, ));

0 个答案:

没有答案