Skip to content

Instantly share code, notes, and snippets.

@visionNoob
Last active July 15, 2019 06:16
Show Gist options
  • Save visionNoob/80c430a2c80483e59967f582bbcf2df2 to your computer and use it in GitHub Desktop.
Save visionNoob/80c430a2c80483e59967f582bbcf2df2 to your computer and use it in GitHub Desktop.
mxnet record viewing.
import os, tarfile, subprocess
import mxnet as mx
from mxnet import gluon, nd, image
from mxnet.gluon.data.vision import transforms
from gluoncv import utils
from gluoncv.model_zoo import get_model
import matplotlib.pyplot as plt
import numpy as np
# gluoncv 같은게 없다고 할 수 도 있는데 그럼 그냥 위에서 빼셈 ㅋ
data_iter = mx.io.ImageRecordIter(
path_imglist=os.path.join(DATASET_PATH,'cropped_images','records','val1', 'kaggle-car-val1.lst'),
path_imgrec=os.path.join(DATASET_PATH,'cropped_images','records','val1','kaggle-car-val1.rec'),
path_imgidx=os.path.join(DATASET_PATH,'cropped_images','records','val1','kaggle-car-val1.idx'),
data_shape=(3, 224, 224),label_width=1, # output data shape. An 227x227 region will be cropped from the original image.
batch_size=4,rand_crop=True, # number of samples per batch
resize=256, pad=1 # resize the shorter edge to 256 before cropping
# ... you can add more augmentation options as defined in ImageRecordIter.
)
data_iter.reset()
batch = data_iter.next()
data = batch.data[0]
for i in range(4):
plt.subplot(1,4,i+1)
plt.imshow(data[i].asnumpy().astype(np.uint8).transpose((1,2,0)))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment