table of Contents
1. list method
index()
: Return only the first query to the index value.
To return plurality, and deriving a list of suggestedmax()
methods, one by one can compare.
2. the
Check the directory exists, it does not exist, create
if not os.path.exists(dir_save_stack): os.makedirs(dir_save_stack) # 如果是单层目录,可以用mkdir
3. imageio
Png a grayscale image stored array is
assumed that the Y channel after treatment, to obtain a between [0,1] as the typenp.float32
of arrayoutput
. We want to save theoutput_path
path, the steps of: eliminate redundant dimensions B and C => departing from the gradient operation, is transferred to the CPU, it is converted to an array numpy => by 255 => converted to auint8
format =>imageio.imwrite
Save.imageio.imwrite(output_path, ((torch.squeeze(output).detach().cpu().numpy()) * 255).astype(np.uint8))
Warning: I have tried to save as png, the resulting image is a lossy compression. If you need further treatment (such as count psnr), recommended saved as bmp.
4. Python Image Libarary (PIL)
JPEG compression and save
from PIL import Image img = Image.open("lena.png") img.save(img_save_path, "JPEG", quality=quality) # quality = 1 is the worst, quality = 95 is the best
5. random
Press the seeds upset sequence
random.seed(17) random.shuffle(order)
6. time
time.time()
: Returns units, from January 1970 midnight on the 1st (epoch) elapsed time in seconds.