def readPngFile(filename): ''' Read a single PNG file filename = fully qualified file name Return: 3D numpy array (rows x cols x chans) Note: all pixel values are floats in the range 0.0 .. 1.0 This implementation relies on the pypng package ''' #print("reading:", filename) # Load in the image meta-data r = png.Reader(filename) it = r.read() # Load in the image itself and convert to a 2D array image_2d = np.vstack(map(np.uint8, it[2])) # Reshape into rows x cols x chans image_3d = np.reshape(image_2d, (it[0],it[1],it[3]['planes'])) / 255.0 return image_3d def read_images_from_directory(directory, file_regexp): ''' Read a set of images from a directory. All of the images must be the directory = Directory to search file_regexp = a regular expression to match the file names against Return: 4D numpy array (images x rows x cols x chans) ''' # Get all of the file names files = sorted(os.listdir(directory)) # Construct a list of images from those list_of_images = [readPngFile(directory + "/" + f) for f in files if re.search(file_regexp, f) ] # Create a 3D numpy array return np.array(list_of_images, dtype=np.float32) def read_image_set_from_directories(directory, spec): ''' Read a set of images from a set of directories directory = base directory to read from spec = n x 2 array of subdirs and file regexps Return: 4D numpy array (images x rows x cols x chans) ''' out = read_images_from_directory(directory + "/" + spec[0][0], spec[0][1]) for sp in spec[1:]: out = np.append(out, read_images_from_directory(directory + "/" + sp[0], sp[1]), axis=0) return out
Here is an example of using the top-level function to create a data set in which th cans are positive examples of the class and mugs are negative examples:
directory2 = '/home2/fagg/datasets/core50/core50_128x128/s1' ins_pos = read_image_set_from_directories(directory2, [['o21', '.*00.png'], ['o22', '.*00.png']]) ins_neg = read_image_set_from_directories(directory2, [['o41', '.*00.png'], ['o42', '.*00.png']]) outs_pos = np.ones(ins_pos.shape[0]) outs_neg = np.zeros(ins_neg.shape[0]) ins = np.append(ins_pos, ins_neg, axis=0) outs = np.append(outs_pos, outs_neg, axis=0)Note that this is a tiny example: we are only loading in one out of every 100 images. In practice, you should be able to load and process all of these files.
Compute and report validation PSS or AUC as a function of training epoch. At the very least, validation data should come from a different condition from the training data. In the best case, the validation data comes from a different object (e.g., o41 vs o45).
For at least two different network architectures and at least two different choices for network parameters (e.g., filter size or hidden unit number), show validation PSS or AUC as a function of training epoch. These results are best shown on one figure.
plt.imshow(ins_neg[2,:,:,:].astype(np.float32))
Last modified: Thu Apr 5 21:37:18 2018