MCPcopy Create free account
hub / github.com/UVA-Computer-Vision-Lab/FrameINO / INO_DINO_evaluation

Function INO_DINO_evaluation

evaluation/evaluate_INO_DINO.py:28–200  ·  view source on GitHub ↗

Args: num_frames (int): If this is none, it means that we need find gen frames num by ourselves test_num_frames (int): how many frames to be selected in the generated results

(data_parent_path, target_height, target_width, test_num_frames=None)

Source from the content-addressed store, hash-verified

26
27
28def INO_DINO_evaluation(data_parent_path, target_height, target_width, test_num_frames=None):
29 '''
30 Args:
31 num_frames (int): If this is none, it means that we need find gen frames num by ourselves
32 test_num_frames (int): how many frames to be selected in the generated results
33 '''
34
35 # Init the Dino model
36 device = "cuda"
37 dinov2_dict = {
38 'repo_or_dir': f'facebookresearch/dinov2',
39 'model': 'dinov2_vitb14',
40 }
41 dinov2_model = torch.hub.load(**dinov2_dict).to(device)
42
43
44
45 # Image transforms
46 image_transform = dino_transform_Image(224)
47
48
49 # Calculate the MAX nubmer of frames in video folder
50 total_gen_num_frames_one_video, total_gt_num_frames_one_video = 0, 0
51 for file_name in sorted(os.listdir(os.path.join(data_parent_path, "instance0"))):
52 if file_name.find("gen_frame") != - 1:
53 total_gen_num_frames_one_video += 1
54
55 if file_name.find("gt_frame") != - 1:
56 total_gt_num_frames_one_video += 1
57 print("We have total gen and gt number in one video of frames of ", total_gen_num_frames_one_video, total_gt_num_frames_one_video)
58
59
60
61
62 # Iterate each sub folder
63 all_video_score = []
64 for instance_idx in range(len(os.listdir(data_parent_path))):
65 sub_folder_path = os.path.join(data_parent_path, "instance"+str(instance_idx))
66
67 # Read the main reference img
68 reference_img_path = os.path.join(sub_folder_path, "Main_Reference.png")
69 assert(os.path.exists(reference_img_path))
70
71 # Resize & Transform
72 reference_img = Image.open(reference_img_path)
73 reference_img = reference_img.resize((target_width, target_height))
74 reference_img = image_transform(reference_img)
75
76
77 # Convert
78 reference_img = reference_img.unsqueeze(0)
79 reference_img = reference_img.to(device)
80
81 # Input DINO V2
82 reference_image_features = dinov2_model(reference_img)
83 reference_image_features = F.normalize(reference_image_features, dim=-1, p=2)
84
85

Callers 1

mass_evaluationFunction · 0.90

Calls 2

dino_transform_ImageFunction · 0.85
toMethod · 0.45

Tested by

no test coverage detected