Tensorflow machine learning portal --cifar10 data set to read, display and save

  • Basic Information
  • Data set directory structure after downloading codecs:
  • Read, print and save images of the specified data set:
    import pickle
    import matplotlib.pyplot as plt
    
    CIFAR_DIR = " cifar10_data / CIFAR-10-bin-Batches / data_batch_1.bin " # dataset path 
    with Open (CIFAR_DIR, ' RB ' ) AS F:
        data = pickle.load(f, encoding='bytes')
    
    Print ( ' ---------- batch1 the basic information ------------- ' )    
     Print ( ' Data Type Data: ' , type (Data)) # Output < class' dict '> 
    Print ( ' dictionary key name: ' , data.keys ()) # output dict_keys ([b'filenames', b'data', b'labels', b'batch_label ']) 
    Print ( ' bdata datatype ' , type (data [B ' data ' ])) # output <class' numpy.ndarray'> 
    Print ( ' bdata shape data ' ,data[b'data'] .shape) # output (10000, 3072) Description of 10,000 samples, 3,072 feature 
    
    index =. 4 # print first few images
     Print ( ' -----------% d of Image - --------- ' % index)
     Print ( ' of the filenames: ' , Data [B ' of the filenames ' ] [index])
     Print ( ' Labels: ' , Data [B ' Labels ' ] [index])
     Print ( ' batch_label: ' , Data [B ' batch_label ' ] [index])
    image_arr = Data [B ' Data ' ] [index] # Take the first sample index 
    image_arr image_arr.reshape = ((. 3, 32, 32)) # will change the shape of one-dimensional vectors to obtain a high :( such a tuple, width , channels) 
    image_arr image_arr.transpose = ((. 1, 2 , 0))
    plt.imshow (image_arr) # output picture 
    plt.savefig ( " cifar10_data / RAW /% d.png " % index) # save the image 
    plt.show ()
  • Print out pictures
  •  

     

Guess you like

Origin www.cnblogs.com/Fengqiao/p/cifar10_read.html