machine learning - How to create dataset similar to cifar-10 -
i want create dataset has same format cifar-10 data set use tensorflow. should have images , labels. basically, i'd able take cifar-10 code different images , labels, , run code. haven't found information on how online, , new machine learning.
i have run cifar10 code on few of own data sets. believe should able give answer.
before though, need understand format in cifar10 data set in. if refer to: https://www.cs.toronto.edu/~kriz/cifar.html, , specifically, binary version section, see this:
in other words, first byte label of first image, number in range 0-9. next 3072 bytes values of pixels of image. first 1024 bytes red channel values, next 1024 green, , final 1024 blue. values stored in row-major order, first 32 bytes red channel values of first row of image.
intuitively, need store data in format. can next sort of baseline experiment first, images same size , same number of classes cifar10 , put them in format. means images should have size of 32x32x3 , have 10 classes. if can run this, can go further on factor cases single channels, different size inputs, , different classes. doing mean have change many variables in other parts of code. have work way through.
i'm in midst of working out general module. code in https://github.com/jkschin/svhn. if refer svhn_flags.py code, see many flags there can changed accommodate needs. admit it's cryptic now, haven't cleaned such readable, works. if willing spend time taking rough look, figure out.
this easy way run own data set on cifar10. of course copy neural network definition , implement own reader, input format, batching, etc, if want , running fast, tune inputs fit cifar10.
i hope helps.
edit:
some really basic code hope help.
from pil import image import numpy np im = image.open('images.jpeg') im = (np.array(im)) r = im[:,:,0].flatten() g = im[:,:,1].flatten() b = im[:,:,2].flatten() label = [1] out = np.array(list(label) + list(r) + list(g) + list(b),np.uint8) out.tofile("out.bin")
this convert image byte file ready use in cifar10. multiple images, keep concatenating arrays, stated in format above. check if format correct, asker's use case, should file size of 427*427*3 + 1 = 546988 bytes. assuming pictures rgb , values range 0-255. once verify that, you're set run in tensorflow. use tensorboard perhaps visualize 1 image, guarantee correctness.
edit 2:
as per asker's question in comments,
if not eval_data: filenames = [os.path.join(data_dir, 'data_batch_%d.bin' % i) in xrange(1, 6)]
if wanna work is, need study function calls of cifar10 code. in cifar10_input, batches hardcoded. have edit line of code fit name of bin file. or, distribute images 6 bin files evenly.
Comments
Post a Comment