R, G, B = ([], [], []) ## loop over datasets for dtype, dinfo in datasets.items(): paths, labels, hdfpath = dinfo print("[INFO] building dataset = ", dtype, ", labels distribution =", Counter(labels)) # build a hdf writer writer = HDF5DatasetWriter(hdfpath, (len(paths), 256, 256, 3)) # loop over the image paths & preprocess images for i in tqdm(range(len(paths))): path, label = paths[i], labels[i] image = cv2.imread(path) image = aap.preprocess(image) # save mean values of RGB channels for train set if dtype == "train": b, g, r = cv2.mean(image)[:3] R.append(r) G.append(g) B.append(b) # feed image & label to writer buffer writer.add([image], [label]) pass # close writer writer.close() pass
predictions = [] submission = pd.read_csv("./sample_submission.csv") # columns = [id,label] # preprocess batch images & do prediction if useTTA == "True": print("[INFO] applying TTA..") else: print("[INFO] NOT applying TTA..") # loop over batches for i in tqdm(range(0, N, B)): batchPaths = imagePaths[i:i + B] batchImages = [] for path in batchPaths: image = cv2.imread(path) image = aap.preprocess(image) # maintain AR and resize to 256 x 256 image = iap.preprocess(image) # Special for ImageNet dataset => substracting mean RGB pixel intensity image = imagenet_utils.preprocess_input(image) # (256, 256, 3) batchImages.append(image) pass if useTTA == "True": for image in batchImages: crops = cp1.preprocess(image) # predict over 10 crops crops_probs = model.predict(crops) # predict probs of dogs pred = crops_probs.mean(axis=0)[1]