def display_fig(name, figure_A, figure_B): figure = np.concatenate([figure_A, figure_B], axis=0 ) columns = 4 elements = figure.shape[0] figure = figure.reshape((columns,(elements//columns)) + figure.shape[1:]) figure = stack_images(figure) figure = np.clip((figure + 1) * 255 / 2, 0, 255).astype('uint8') display_fn(figure, name)
def show_sample(self): """ Display preview data """ if len(self.images) != 2: logger.debug("Ping Pong training - Only one side trained. Aborting preview") return None logger.debug("Showing sample") feeds = dict() figures = dict() headers = dict() for side, samples in self.images.items(): faces = samples[1] if self.model.input_shape[0] / faces.shape[1] != 1.0: feeds[side] = self.resize_sample(side, faces, self.model.input_shape[0]) feeds[side] = feeds[side].reshape((-1, ) + self.model.input_shape) else: feeds[side] = faces if self.use_mask: mask = samples[-1] feeds[side] = [feeds[side], mask] preds = self.get_predictions(feeds["a"], feeds["b"]) for side, samples in self.images.items(): other_side = "a" if side == "b" else "b" predictions = [preds["{}_{}".format(side, side)], preds["{}_{}".format(other_side, side)]] display = self.to_full_frame(side, samples, predictions) headers[side] = self.get_headers(side, other_side, display[0].shape[1]) figures[side] = np.stack([display[0], display[1], display[2], ], axis=1) if self.images[side][0].shape[0] % 2 == 1: figures[side] = np.concatenate([figures[side], np.expand_dims(figures[side][0], 0)]) width = 4 side_cols = width // 2 if side_cols != 1: headers = self.duplicate_headers(headers, side_cols) header = np.concatenate([headers["a"], headers["b"]], axis=1) figure = np.concatenate([figures["a"], figures["b"]], axis=0) height = int(figure.shape[0] / width) figure = figure.reshape((width, height) + figure.shape[1:]) figure = stack_images(figure) figure = np.vstack((header, figure)) logger.debug("Compiled sample") return np.clip(figure * 255, 0, 255).astype('uint8')
def show_sample(self): """ Display preview data """ if len(self.images) < 2: logger.debug( "Ping Pong training - Only one side trained. Aborting preview") return None logger.debug("Showing sample") feeds = dict() figures = dict() headers = dict() for side, samples in self.images.items(): side = side[-1] faces = samples[1] if self.model.input_shape[0] / faces.shape[1] != 1.0: feeds[side] = self.resize_sample(side, faces, self.model.input_shape[0]) feeds[side] = feeds[side].reshape((-1, ) + self.model.input_shape) else: feeds[side] = faces preds = self.get_predictions(feeds) for side, samples in self.images.items(): predictions = [ preds["{}_{}".format(other_side, side[-1])] for other_side in range(len(feeds)) ] #print(f"------predictions len = {len(predictions)}") display = self.to_full_frame(side, samples, predictions) #headers[side] = self.get_headers(side, len(feeds), display[0].shape[1]) #print(f"-----------display len = {len(display)}") figures[side] = np.stack(display, axis=1) width = len(feeds) + 1 #header = np.concatenate([headers["0"], headers["1"]], axis=1) #print(f"---------------------------------figures len = {figures['1'].shape}") figure = np.concatenate([figures[key] for key in figures], axis=1) #print(f"-----------------------------------{figure.shape}") height = len(feeds) figure = figure.reshape((height, width) + figure.shape[2:]) figure = stack_images(figure) #figure = np.vstack((header, figure)) logger.debug("Compiled sample") return np.clip(figure * 255, 0, 255).astype('uint8')
def show_sample(self, test_A, test_B): figure_A = numpy.stack([ test_A, self.model.autoencoder_A.predict(test_A), self.model.autoencoder_B.predict(test_A), ], axis=1) figure_B = numpy.stack([ test_B, self.model.autoencoder_B.predict(test_B), self.model.autoencoder_A.predict(test_B), ], axis=1) figure = numpy.concatenate([figure_A, figure_B], axis=0) figure = figure.reshape((4, 7) + figure.shape[1:]) figure = stack_images(figure) return numpy.clip(figure * 255, 0, 255).astype('uint8')
def show_sample(self, test_A, test_B): figure_A = numpy.stack([ test_A, self.model.autoencoder_A.predict(test_A), self.model.autoencoder_B.predict(test_A), ], axis=1) figure_B = numpy.stack([ test_B, self.model.autoencoder_B.predict(test_B), self.model.autoencoder_A.predict(test_B), ], axis=1) figure = numpy.concatenate([figure_A, figure_B], axis=0) figure = figure.reshape((4, 7) + figure.shape[1:]) figure = stack_images(figure) return numpy.clip(figure * 255, 0, 255).astype('uint8')
def showG_mask(self, test_A, test_B, path_A, path_B): figure_A = np.stack([ test_A, (np.squeeze(np.array([path_A([test_A[i:i+1]]) for i in range(test_A.shape[0])])))*2-1, (np.squeeze(np.array([path_B([test_A[i:i+1]]) for i in range(test_A.shape[0])])))*2-1, ], axis=1 ) figure_B = np.stack([ test_B, (np.squeeze(np.array([path_B([test_B[i:i+1]]) for i in range(test_B.shape[0])])))*2-1, (np.squeeze(np.array([path_A([test_B[i:i+1]]) for i in range(test_B.shape[0])])))*2-1, ], axis=1 ) figure = np.concatenate([figure_A, figure_B], axis=0 ) figure = figure.reshape((4,self.batch_size // 2) + figure.shape[1:]) figure = stack_images(figure) figure = np.clip((figure + 1) * 255 / 2, 0, 255).astype('uint8') return figure
def show_sample(self, test_A, test_B): AA = self.model.autoencoder_A.predict(test_A) BA = self.model.autoencoder_B.predict(test_A) BB = self.model.autoencoder_B.predict(test_B) AB = self.model.autoencoder_A.predict(test_B) figure_A = numpy.stack( [ test_A, #self.model.autoencoder_A.predict(test_A), AA, #self.model.autoencoder_B.predict(test_A), BA, ], axis=1) figure_B = numpy.stack( [ test_B, #self.model.autoencoder_B.predict(test_B), BB, #self.model.autoencoder_A.predict(test_B), AB, ], axis=1) if (test_A.shape[0] % 2) != 0: figure_A = numpy.concatenate( [figure_A, numpy.expand_dims(figure_A[0], 0)]) figure_B = numpy.concatenate( [figure_B, numpy.expand_dims(figure_B[0], 0)]) figure = numpy.concatenate([figure_A, figure_B], axis=0) w = 4 h = int(figure.shape[0] / w) figure = figure.reshape((w, h) + figure.shape[1:]) figure = stack_images(figure) return numpy.clip(figure * 255, 0, 255).astype('uint8')
def show_sample(self, test_A, test_B): figure_A = numpy.stack([ test_A, autoencoder_A.predict(test_A), autoencoder_B.predict(test_A), ], axis=1) figure_B = numpy.stack([ test_B, autoencoder_B.predict(test_B), autoencoder_A.predict(test_B), ], axis=1) figure = numpy.concatenate([figure_A, figure_B], axis=0) figure = figure.reshape((4, 7) + figure.shape[1:]) figure = stack_images(figure) figure = numpy.clip(figure * 255, 0, 255).astype('uint8') if self.arguments.preview is True: cv2.imshow('', figure) if not self.arguments.preview or self.arguments.write_image: cv2.imwrite('_sample.jpg', figure)
def show_sample(self, test_A, test_B): figure_A = numpy.stack([ test_A, self.model.autoencoder_A.predict(test_A), self.model.autoencoder_B.predict(test_A), ], axis=1) figure_B = numpy.stack([ test_B, self.model.autoencoder_B.predict(test_B), self.model.autoencoder_A.predict(test_B), ], axis=1) if test_A.shape[0] % 2 == 1: figure_A = numpy.concatenate ([figure_A, numpy.expand_dims(figure_A[0],0) ]) figure_B = numpy.concatenate ([figure_B, numpy.expand_dims(figure_B[0],0) ]) figure = numpy.concatenate([figure_A, figure_B], axis=0) w = 4 h = int( figure.shape[0] / w) figure = figure.reshape((w, h) + figure.shape[1:]) figure = stack_images(figure) return numpy.clip(figure * 255, 0, 255).astype('uint8')