def style_transfer_high_resolution(patches, sFs, padding, collection, save_path, save=True, wct_mode="cpu"): stylized_patches = [] init_thumbnail_instance_norm(wct, collection=collection) for patch in tqdm(patches): patch = patch.unsqueeze(0).to(device) stylized_patch = styleTransfer(patch, sFs, wct_mode) stylized_patch = F.interpolate(stylized_patch, patch.shape[2:], mode='bilinear', align_corners=True) stylized_patch = unpadding(stylized_patch, padding=padding) stylized_patches.append(stylized_patch.cpu()) stylized_patches = torch.cat(stylized_patches, dim=0) b, c, h, w = stylized_patches.shape stylized_patches = stylized_patches.unsqueeze(dim=0) stylized_patches = stylized_patches.view(1, b, c * h * w).permute( 0, 2, 1).contiguous() output_size = (int(math.sqrt(b) * h), int(math.sqrt(b) * w)) stylized_image = F.fold(stylized_patches, output_size=output_size, kernel_size=(h, w), stride=(h, w)) if save: save_image(stylized_image, save_path)
def decompress_speck(path, dest_path): if path[-1] != "/": path += "/" info = pickle.load(open(path + "info.dat", "r")) if not os.path.exists(dest_path): os.makedirs(dest_path) codec = sk.speck() for c in range(info.frames): frame = pickle.load(open(path + str(c) + ".speck","rb")) wavelet = codec.expand(frame["payload"], info.wavelet_cols, info.wavelet_rows, info.wavelet_level, frame["wise_bit"]) iframe = lwt.icdf97(wavelet) iframe = tools.aquant(iframe, 100000) iframe = tools.unpadding(iframe, (info.rows, info.cols)) if not cv2.imwrite(dest_path + str(c) + ".png", iframe, [cv2.cv.CV_IMWRITE_PNG_COMPRESSION, 0]): print "Failed to create: " + dest_path + str(c) + ".png" pickle.dump(info, open(dest_path + "info.dat", "w"))
def style_transfer_high_resolution(patches, sF, padding, save_path, collection=False, save=True): stylized_patches = [] init_thumbnail_instance_norm(matrix, collection=collection) for patch in tqdm(patches): patch = patch.unsqueeze(0).to(device) cF = vgg(patch) if (args.layer == 'r41'): feature = matrix(cF[args.layer], sF[args.layer]) else: feature = matrix(cF, sF) stylized = dec(feature) stylized = F.interpolate(stylized, patch.shape[2:], mode='bilinear', align_corners=True) stylized = unpadding(stylized, padding=padding) stylized_patches.append(stylized.cpu()) stylized_patches = torch.cat(stylized_patches, dim=0) b, c, h, w = stylized_patches.shape stylized_patches = stylized_patches.unsqueeze(dim=0) stylized_patches = stylized_patches.view(1, b, c * h * w).permute(0, 2, 1).contiguous() output_size = (int(math.sqrt(b) * h), int(math.sqrt(b) * w)) stylized_image = F.fold(stylized_patches, output_size=output_size, kernel_size=(h, w), stride=(h, w)) if save: save_image(stylized_image, save_path)