Skip to content

Instantly share code, notes, and snippets.

@tomellis
Created November 19, 2018 15:51
Show Gist options
  • Save tomellis/29e561b7e957c8bdb16eff30a8375762 to your computer and use it in GitHub Desktop.
Save tomellis/29e561b7e957c8bdb16eff30a8375762 to your computer and use it in GitHub Desktop.
Extract images from recordio format
from mxnet import recordio
import mxnet as mx
import cv2
import matplotlib.pyplot as plt
from PIL import Image
record = mx.recordio.MXRecordIO('mlclassify_train.rec', 'r')
i = 0
while True:
item = record.read()
if not item:
break
header, img = mx.recordio.unpack_img(item)
filename = "aeroplane%s.jpg" % i
cv2.imwrite(filename, img)
i += 1
b,g,r = cv2.split(img)
img = cv2.merge([r,g,b])
plt.imshow(img)
record.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment