In [1]:
import mxnet as mx
import matplotlib.pyplot as plt
import numpy as np
%pylab inline
pylab.rcParams['figure.figsize'] = (2, 3)
Populating the interactive namespace from numpy and matplotlib
In [8]:
# Step 1 data
# input data debug
data_iter = mx.io.ImageRecordIter(
path_imgrec = 'data/cifar10_train.rec',
data_shape = (3,28,28),
label_width = 1,
batch_size = 128
)
print (data_iter)
i = 0
for each in data_iter:
i+=1
if i>5:
break
print each
batch_numpy = each.data[0].asnumpy()
label_numpy = each.label[0].asnumpy()
print (type(batch_numpy))
print (type(label_numpy))
#show img
randidx = np.random.randint(0,128)
img = batch_numpy[randidx]
img = np.squeeze(img).sum(axis=0)
plt.imshow(img, cmap='gray')
plt.show()
<mxnet.io.MXDataIter object at 0x7f951f4e01d0>
DataBatch: data shapes: [(128L, 3L, 28L, 28L)] label shapes: [(128L,)]
DataBatch: data shapes: [(128L, 3L, 28L, 28L)] label shapes: [(128L,)]
DataBatch: data shapes: [(128L, 3L, 28L, 28L)] label shapes: [(128L,)]
DataBatch: data shapes: [(128L, 3L, 28L, 28L)] label shapes: [(128L,)]
DataBatch: data shapes: [(128L, 3L, 28L, 28L)] label shapes: [(128L,)]
<type 'numpy.ndarray'>
<type 'numpy.ndarray'>
In [9]:
# debug model
from importlib import import_module
net = import_module('symbols.'+'resnet')
sym = net.get_symbol(10,20,"3,28,28")
model_prefix = 'cifar10_resnet'
#check_point = mx.callback.do_checkpoint(model_prefix)
arg_name = sym.list_arguments()
out_name = sym.list_outputs()
print (arg_name)
print (out_name)
mx.viz.plot_network(sym,hide_weights=True,save_format='pdf',title='resnet8')
['data', 'bn_data_gamma', 'bn_data_beta', 'conv0_weight', 'stage1_unit1_bn1_gamma', 'stage1_unit1_bn1_beta', 'stage1_unit1_conv1_weight', 'stage1_unit1_bn2_gamma', 'stage1_unit1_bn2_beta', 'stage1_unit1_conv2_weight', 'stage1_unit1_sc_weight', 'stage1_unit2_bn1_gamma', 'stage1_unit2_bn1_beta', 'stage1_unit2_conv1_weight', 'stage1_unit2_bn2_gamma', 'stage1_unit2_bn2_beta', 'stage1_unit2_conv2_weight', 'stage1_unit3_bn1_gamma', 'stage1_unit3_bn1_beta', 'stage1_unit3_conv1_weight', 'stage1_unit3_bn2_gamma', 'stage1_unit3_bn2_beta', 'stage1_unit3_conv2_weight', 'stage2_unit1_bn1_gamma', 'stage2_unit1_bn1_beta', 'stage2_unit1_conv1_weight', 'stage2_unit1_bn2_gamma', 'stage2_unit1_bn2_beta', 'stage2_unit1_conv2_weight', 'stage2_unit1_sc_weight', 'stage2_unit2_bn1_gamma', 'stage2_unit2_bn1_beta', 'stage2_unit2_conv1_weight', 'stage2_unit2_bn2_gamma', 'stage2_unit2_bn2_beta', 'stage2_unit2_conv2_weight', 'stage2_unit3_bn1_gamma', 'stage2_unit3_bn1_beta', 'stage2_unit3_conv1_weight', 'stage2_unit3_bn2_gamma', 'stage2_unit3_bn2_beta', 'stage2_unit3_conv2_weight', 'stage3_unit1_bn1_gamma', 'stage3_unit1_bn1_beta', 'stage3_unit1_conv1_weight', 'stage3_unit1_bn2_gamma', 'stage3_unit1_bn2_beta', 'stage3_unit1_conv2_weight', 'stage3_unit1_sc_weight', 'stage3_unit2_bn1_gamma', 'stage3_unit2_bn1_beta', 'stage3_unit2_conv1_weight', 'stage3_unit2_bn2_gamma', 'stage3_unit2_bn2_beta', 'stage3_unit2_conv2_weight', 'stage3_unit3_bn1_gamma', 'stage3_unit3_bn1_beta', 'stage3_unit3_conv1_weight', 'stage3_unit3_bn2_gamma', 'stage3_unit3_bn2_beta', 'stage3_unit3_conv2_weight', 'bn1_gamma', 'bn1_beta', 'fc1_weight', 'fc1_bias', 'softmax_label']
['softmax_output']
Out[9]:
In [ ]:
In [2]:
Help on function ImageRecordIter in module mxnet.io:
ImageRecordIter(*args, **kwargs)
Iterating on image RecordIO files
Read images batches from RecordIO files with a rich of data augmentation
options.
One can use ``tools/im2rec.py`` to pack individual image files into RecordIO
files.
Defined in src/io/iter_image_recordio_2.cc:L568
Parameters
----------
path_imglist : string, optional, default=''
Path to the image list file
path_imgrec : string, optional, default=''
Filename of the image RecordIO file or a directory path.
aug_seq : string, optional, default='aug_default'
The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.
label_width : int, optional, default='1'
The number of labels per image.
data_shape : Shape(tuple), required
The shape of one output image.
preprocess_threads : int, optional, default='4'
The number of threads.
verbose : boolean, optional, default=True
If or not output verbose information.
num_parts : int, optional, default='1'
Virtual partition data into *n* parts
part_index : int, optional, default='0'
The *i*-th virtual partition will read
shuffle_chunk_size : long (non-negative), optional, default=0
The data shuffle buffer size in MB. Only valid if shuffle is true
shuffle_chunk_seed : int, optional, default='0'
The random seed for shuffling
shuffle : boolean, optional, default=False
If or not randomly shuffle data.
seed : int, optional, default='0'
The random seed.
batch_size : int (non-negative), required
Batch size.
round_batch : boolean, optional, default=True
If or not use round robin to handle overflow batch.
prefetch_buffer : long (non-negative), optional, default=4
Maximal Number of batches to prefetch
dtype : {None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None'
Output data type. None means no change
resize : int, optional, default='-1'
Down scale the shorter edge to a new size before applying other augmentations.
rand_crop : boolean, optional, default=False
If or not randomly crop the image
max_rotate_angle : int, optional, default='0'
Rotate by a random degree in ``[-v, v]``
max_aspect_ratio : float, optional, default=0
Change the aspect (namely width/height) to a random value in ``[1 - max_aspect_ratio, 1 + max_aspect_ratio]``
max_shear_ratio : float, optional, default=0
Apply a shear transformation (namely ``(x,y)->(x+my,y)``) with ``m`` randomly chose from ``[-max_shear_ratio, max_shear_ratio]``
max_crop_size : int, optional, default='-1'
Crop both width and height into a random size in ``[min_crop_size, max_crop_size]``
min_crop_size : int, optional, default='-1'
Crop both width and height into a random size in ``[min_crop_size, max_crop_size]``
max_random_scale : float, optional, default=1
Resize into ``[width*s, height*s]`` with ``s`` randsomly chosen from ``[min_random_scale, max_random_scale]``
min_random_scale : float, optional, default=1
Resize into ``[width*s, height*s]`` with ``s`` randsomly chosen from ``[min_random_scale, max_random_scale]``
max_img_size : float, optional, default=1e+10
Set the maximal width and height after all resize and rotate argumentation are applied
min_img_size : float, optional, default=0
Set the minimal width and height after all resize and rotate argumentation are applied
random_h : int, optional, default='0'
Add a random value in ``[-random_h, random_h]`` to the H channel in HSL color space.
random_s : int, optional, default='0'
Add a random value in ``[-random_s, random_s]`` to the S channel in HSL color space.
random_l : int, optional, default='0'
Add a random value in ``[-random_l, random_l]`` to the L channel in HSL color space.
rotate : int, optional, default='-1'
Rotate by an angle. If set, it overrites the ``max_rotate_angle`` option.
fill_value : int, optional, default='255'
Set the padding pixes value into ``fill_value``.
inter_method : int, optional, default='1'
The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.
pad : int, optional, default='0'
Change size from ``[width, height]`` into ``[pad + width + pad, pad + height + pad]`` by padding pixes
mirror : boolean, optional, default=False
If or not mirror the image.
rand_mirror : boolean, optional, default=False
If or not randomly the image.
mean_img : string, optional, default=''
Filename of the The mean image.
mean_r : float, optional, default=0
The mean value to be subtracted on the R channel
mean_g : float, optional, default=0
The mean value to be subtracted on the G channel
mean_b : float, optional, default=0
The mean value to be subtracted on the B channel
mean_a : float, optional, default=0
The mean value to be subtracted on the alpha channel
scale : float, optional, default=1
Multiply the image with a scale value.
max_random_contrast : float, optional, default=0
Change the contrast with a value randomly chosen from ``[-max_random_contrast, max_random_contrast]``
max_random_illumination : float, optional, default=0
Change the illumination with a value randomly chosen from ``[-max_random_illumination, max_random_illumination]``
Returns
-------
MXDataIter
The result iterator.
Content source: RichardTMR/homework
Similar notebooks: