def gen_layers_for_image(i, img): """ Generate laplacian pyramids and normalize every channel of every pyramid. """ img = resize(img[:, :, :], requested_shape) new_imgs = yuv_laplacian_norm(img, requested_shape, 3) return i, new_imgs
def gen_layers_for_image_hog(i, img): """ Generate laplacian pyramids and normalize every channel of every pyramid of RGB. Calc HOG of depth at every scale. """ img = resize(img[:, :, :], requested_shape) rgb_img = img[:, :, 0:3] depth_img = img[:, :, 3] # transform rgb_imgs = yuv_laplacian_norm(rgb_img, requested_shape, n_layers=3) # depth_img = calc_hog(depth_img) depth_img = depth_img.astype('float32') / 255.0 new_imgs = [] for img in rgb_imgs: shp = (img.shape[1], img.shape[2]) new_img = np.concatenate( (img, resize(depth_img, shp).reshape((1, shp[0], shp[1]))), axis=0) new_imgs.append(new_img) return i, new_imgs
def get_stats(results, y, n_classes, dont_care_classes, fnames_path, dataset_type, show=False, log=True, postproc=None, postproc_params=None): assert(len(results) == y.shape[0]) fnames = [] with open(fnames_path, 'r') as f: fnames = f.read().split('\n') care_classes = np.ones((n_classes), dtype='int8') care_classes[dont_care_classes] = 0 correct = np.zeros((n_classes), dtype='int32') total = np.zeros((n_classes), dtype='int32') for ind, img in enumerate(results): curr_y = y[ind] img_up = zoom(img, 4, order=0) img_old = img_up assert(img_up.shape[0] == SHAPE[0]) images_path = IMGS orig_img = open_image(images_path, fnames[ind] + '.jpg') orig_img = resize(orig_img, SHAPE) # apply postprocessing if postproc is not None: img_up = postproc(orig_img, img_up, **postproc_params) if show and ind < IMGS_TO_SHOW: bounds = np.linspace(0, 30, 31) # cmap = plt.get_cmap('Paired') cmap = plt.get_cmap('gist_ncar') norm = matplotlib.colors.BoundaryNorm(bounds, cmap.N) plt.subplot(2, 2, 1) plt.axis('off') plt.imshow(orig_img) plt.subplot(2, 2, 2) plt.axis('off') plt.imshow(curr_y, cmap=cmap, norm=norm) plt.subplot(2, 2, 3) plt.axis('off') plt.imshow(img_old, cmap=cmap, norm=norm) plt.subplot(2, 2, 4) plt.axis('off') plt.imshow(img_up, cmap=cmap, norm=norm) plt.show() plt.draw() # count correct pixels for i in range(n_classes): if np.any(curr_y == i): correct[i] += np.sum(np.equal(img_up[curr_y == i], curr_y[curr_y == i])) total[i] += np.sum(curr_y == i) care_correct = correct * care_classes care_total = total * care_classes class_accuracy = calc_class_accuracy(care_correct, care_total) total_acc = (np.sum(care_correct, dtype='float32') / np.sum(care_total)) * 100. if log: logger.info('total pixel accuracy %f %%', total_acc) logger.info('mean class accuracy: %f %%', class_accuracy * 100.) logger.info('per class accuracies: %s', correct.astype('float32') / total) return total_acc
def mark_image(i, img, cc, requested_shape): logger.info("Marking image %d", i) img = resize(img, requested_shape, inter=0) assert(img.shape[:2] == requested_shape) layers = process_out(img, cc, requested_shape) return i, layers
def get_stats(results, y, n_classes, dont_care_classes, fnames_path, dataset_type, show=False, log=True, postproc=None, postproc_params=None): assert (len(results) == y.shape[0]) fnames = [] with open(fnames_path, 'r') as f: fnames = f.read().split('\n') care_classes = np.ones((n_classes), dtype='int8') care_classes[dont_care_classes] = 0 correct = np.zeros((n_classes), dtype='int32') total = np.zeros((n_classes), dtype='int32') for ind, img in enumerate(results): curr_y = y[ind] img_up = zoom(img, 4, order=0) img_old = img_up assert (img_up.shape[0] == SHAPE[0]) images_path = IMGS orig_img = open_image(images_path, fnames[ind] + '.jpg') orig_img = resize(orig_img, SHAPE) # apply postprocessing if postproc is not None: img_up = postproc(orig_img, img_up, **postproc_params) if show and ind < IMGS_TO_SHOW: bounds = np.linspace(0, 30, 31) # cmap = plt.get_cmap('Paired') cmap = plt.get_cmap('gist_ncar') norm = matplotlib.colors.BoundaryNorm(bounds, cmap.N) plt.subplot(2, 2, 1) plt.axis('off') plt.imshow(orig_img) plt.subplot(2, 2, 2) plt.axis('off') plt.imshow(curr_y, cmap=cmap, norm=norm) plt.subplot(2, 2, 3) plt.axis('off') plt.imshow(img_old, cmap=cmap, norm=norm) plt.subplot(2, 2, 4) plt.axis('off') plt.imshow(img_up, cmap=cmap, norm=norm) plt.show() plt.draw() # count correct pixels for i in range(n_classes): if np.any(curr_y == i): correct[i] += np.sum( np.equal(img_up[curr_y == i], curr_y[curr_y == i])) total[i] += np.sum(curr_y == i) care_correct = correct * care_classes care_total = total * care_classes class_accuracy = calc_class_accuracy(care_correct, care_total) total_acc = (np.sum(care_correct, dtype='float32') / np.sum(care_total)) * 100. if log: logger.info('total pixel accuracy %f %%', total_acc) logger.info('mean class accuracy: %f %%', class_accuracy * 100.) logger.info('per class accuracies: %s', correct.astype('float32') / total) return total_acc