def test_uint8_image(self): ''' Tests that uint8 image (pixel values in [0, 255]) is not changed ''' test_image = np.random.randint(0, 256, size=(3, 32, 32), dtype=np.uint8) scale_factor = summary._calc_scale_factor(test_image) assert scale_factor == 1, 'Values are already in [0, 255], scale factor should be 1'
def make_gif(image_seq, fps=4, print_filepath=False, filename=None, filedir=None): #print(debug_sample_tuple[0].shape) idx_dict = { 'orig_depth': 0 } # if len(debug_sample_tuple[idx_dict['orig_depth']].shape) == 3: # print("CHANGING TxWxH => 1xTx1XWxH") # https://github.com/lanpa/tensorboardX/blob/master/tensorboardX/summary.py #tensor = imag tensor = image_seq if len(tensor.shape) == 3: C = 1 T, H, W = tensor.shape elif len(tensor.shape) == 4: T, C, H, W = tensor.shape tensor = tensor.reshape(1, T, C, H, W) # prepare video requires this format tensor = _prepare_video(tensor) scale_factor = _calc_scale_factor(tensor) tensor = tensor.astype(np.float32) tensor = (tensor * scale_factor).astype(np.uint8) #print(tensor) #t, h, w, c = tensor.shape clip = mpy.ImageSequenceClip(list(tensor), fps=fps) if filename is None: filename = tempfile.NamedTemporaryFile(suffix='.gif', delete=False, dir=filedir).name clip.write_gif(filename, verbose=False, progress_bar=False) if print_filepath: print("GIF Path:", filename) return filename
def test_float32_image(self): ''' Tests that float32 image (pixel values in [0, 1]) are scaled correctly to [0, 255] ''' test_image = np.random.rand(3, 32, 32).astype(np.float32) scale_factor = summary._calc_scale_factor(test_image) assert scale_factor == 255, 'Values are in [0, 1], scale factor should be 255'
def test_float32_image(self): ''' Tests that float32 image (pixel values in [0, 1]) are scaled correctly to [0, 255] ''' test_image = tensor_N(shape=(3, 32, 32)) scale_factor = summary._calc_scale_factor(test_image) assert scale_factor == 255, 'Values are in [0, 1], scale factor should be 255'