Jayce-Ping commited on
Commit
d0d1129
·
verified ·
1 Parent(s): acd24d0

Upload Consistency_Annotation/test.ipynb with huggingface_hub

Browse files
Files changed (1) hide show
  1. Consistency_Annotation/test.ipynb +130 -0
Consistency_Annotation/test.ipynb ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 16,
6
+ "id": "5bdfe87c",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import os\n",
11
+ "import json\n",
12
+ "from itertools import combinations\n",
13
+ "IMAGE_DIR = \"/root/siton-tmp/images_divided\""
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": null,
19
+ "id": "fb8c9036",
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "folders = sorted([\n",
24
+ " f for f in os.listdir(IMAGE_DIR)\n",
25
+ " if os.path.isdir(os.path.join(IMAGE_DIR, f)) and not f.startswith('.')\n",
26
+ "])\n",
27
+ "data = []\n",
28
+ "for cnt, idx in enumerate(folders):\n",
29
+ " folder_path = os.path.join(IMAGE_DIR, idx)\n",
30
+ " images = sorted([img for img in os.listdir(folder_path) if img.endswith('.png')])\n",
31
+ " first_indices, second_indices = zip(*[\n",
32
+ " list(map(int, img.split('.')[0].split('_')))\n",
33
+ " for img in images\n",
34
+ " ])\n",
35
+ " first_indices = sorted(set(first_indices))\n",
36
+ " second_indices = sorted(set(second_indices))\n",
37
+ " \n",
38
+ " for i in first_indices:\n",
39
+ " for j in second_indices:\n",
40
+ " ref_img = f\"{i}_{j}.png\"\n",
41
+ " candidates = [\n",
42
+ " [\n",
43
+ " f\"{x}_{y}.png\"\n",
44
+ " for x in first_indices\n",
45
+ " ]\n",
46
+ " for y in second_indices if y != j\n",
47
+ " ]\n",
48
+ " items = [\n",
49
+ " {\n",
50
+ " 'ref_image': ref_img,\n",
51
+ " 'rank_images': cand,\n",
52
+ " 'idx': idx,\n",
53
+ " } for cand in candidates\n",
54
+ " ]\n",
55
+ " data.extend(items)\n"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": 19,
61
+ "id": "36e0603b",
62
+ "metadata": {},
63
+ "outputs": [
64
+ {
65
+ "data": {
66
+ "text/plain": [
67
+ "[{'ref_image': '0_0.png',\n",
68
+ " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
69
+ " 'idx': '0000'},\n",
70
+ " {'ref_image': '0_0.png',\n",
71
+ " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
72
+ " 'idx': '0000'},\n",
73
+ " {'ref_image': '0_1.png',\n",
74
+ " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
75
+ " 'idx': '0000'},\n",
76
+ " {'ref_image': '0_1.png',\n",
77
+ " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
78
+ " 'idx': '0000'},\n",
79
+ " {'ref_image': '0_2.png',\n",
80
+ " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
81
+ " 'idx': '0000'},\n",
82
+ " {'ref_image': '0_2.png',\n",
83
+ " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
84
+ " 'idx': '0000'},\n",
85
+ " {'ref_image': '1_0.png',\n",
86
+ " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
87
+ " 'idx': '0000'},\n",
88
+ " {'ref_image': '1_0.png',\n",
89
+ " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
90
+ " 'idx': '0000'},\n",
91
+ " {'ref_image': '1_1.png',\n",
92
+ " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
93
+ " 'idx': '0000'},\n",
94
+ " {'ref_image': '1_1.png',\n",
95
+ " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
96
+ " 'idx': '0000'}]"
97
+ ]
98
+ },
99
+ "execution_count": 19,
100
+ "metadata": {},
101
+ "output_type": "execute_result"
102
+ }
103
+ ],
104
+ "source": [
105
+ "data[:10]"
106
+ ]
107
+ }
108
+ ],
109
+ "metadata": {
110
+ "kernelspec": {
111
+ "display_name": "pytorch-env",
112
+ "language": "python",
113
+ "name": "python3"
114
+ },
115
+ "language_info": {
116
+ "codemirror_mode": {
117
+ "name": "ipython",
118
+ "version": 3
119
+ },
120
+ "file_extension": ".py",
121
+ "mimetype": "text/x-python",
122
+ "name": "python",
123
+ "nbconvert_exporter": "python",
124
+ "pygments_lexer": "ipython3",
125
+ "version": "3.12.11"
126
+ }
127
+ },
128
+ "nbformat": 4,
129
+ "nbformat_minor": 5
130
+ }