# This Python program is based on features added in Python 3.5. Python 3.7 is recommanded. # Requires Pillow >= 6.0.0 for ImageOps.exif_transpose() in utils.py from PIL import Image import math from os import walk, listdir from os.path import isfile, join import config from image import is_animated, rotate, combineImages from video import animate, getFps, avgFps # Load configuration args = config.args() userconf = config.user(args.config) CONFIG = config.general(args, userconf) CANVAS_ATT = config.canvas(args, userconf) FFMPEG = config.ffmpeg(args, userconf) # Walk in subdirectories (jour 1, jour 2, ...) for root, dirs, _ in walk(CONFIG["ROOT_DIR"]): print("dirs in root: " + str(dirs)) # Debug # For each subdir for subdir in dirs: dir = join(root, subdir) print("current subdir: " + str(dir)) # Debug # Read all the files in the dir & keep only images images = [] for file in listdir(dir): file = join(dir, file) try:
import torch import torchvision from torch.utils.data import DataLoader import torch.nn.functional as F import config from torchvision import transforms from model import SiameseNetwork from utils import SiameseNetworkDataset, imshow opt = config.args() folder_dataset_test = torchvision.datasets.ImageFolder(root=opt.testing_dir) # 定义图像dataset transform_test = transforms.Compose([transforms.Resize((100, 100)), transforms.ToTensor()]) siamese_dataset_test = SiameseNetworkDataset(imageFolderDataset=folder_dataset_test, transform=transform_test, should_invert=False) # 定义图像dataloader test_dataloader = DataLoader(siamese_dataset_test, shuffle=True, batch_size=1) net = SiameseNetwork().cuda() net.load_state_dict(torch.load('checkpoint/siameseNet49.pth')) # 生成对比图像 dataiter = iter(test_dataloader) x0, _, _ = next(dataiter) for i in range(10):
if best_eval['loss'] == 0 or f1 > best_eval['f1']: best_eval['loss'] = epoch_loss best_eval['acc'] = acc best_eval['precision'] = precision best_eval['recall'] = recall best_eval['f1'] = f1 torch.save(bert_crf_tagger, f'{paras.log_save_path}/{paras.model_save_name}') with open(f'{paras.log_save_path}/checkpoint.log', 'w') as wf: wf.write( f'Save time: {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}\n' ) wf.write(f'Best F1-score: {best_eval["f1"]:.4f}\n') wf.write(f'Best Precision: {best_eval["precision"]:.4f}\n') wf.write(f'Best Recall: {best_eval["recall"]:.4f}\n') wf.write(f'Best Accuracy: {best_eval["acc"]:.4f}\n') wf.write(f'Best Loss: {best_eval["loss"]:.4f}\n') logger.info( f'Updated model, best F1-score: {best_eval["f1"]:.4f}\n') if __name__ == '__main__': args = args() set_seed(args.seed) main(args)