Datasets:

Modalities:
Image
Text
Size:
n<1K
ArXiv:
Tags:
License:
myownskyW7 commited on
Commit
1332256
1 Parent(s): 5278dc4

init v3det

Browse files
README.md CHANGED
@@ -1,3 +1,143 @@
1
- ---
2
- license: cc-by-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p>
2
+ <div align="center">
3
+
4
+ # <img src="images/v3det_icon.jpg" height="25"> V3Det: Vast Vocabulary Visual Detection Dataset
5
+
6
+ <div>
7
+ <a href='https://myownskyw7.github.io/' target='_blank'>Jiaqi Wang</a>*,
8
+ <a href='https://panzhang0212.github.io/' target='_blank'>Pan Zhang</a>*,
9
+ Tao Chu*,
10
+ Yuhang Cao*, </br>
11
+ Yujie Zhou,
12
+ <a href='https://wutong16.github.io/' target='_blank'>Tong Wu</a>,
13
+ Bin Wang,
14
+ Conghui He,
15
+ <a href='http://dahua.site/' target='_blank'>Dahua Lin</a></br>
16
+ (* equal contribution)</br>
17
+ <strong>Accepted to ICCV 2023 (Oral)</strong>
18
+ </div>
19
+ </p>
20
+ <p>
21
+ <div>
22
+ <strong>
23
+ <a href='https://arxiv.org/pdf/2304.03752.pdf' target='_blank'>Paper</a>,
24
+ <a href='https://v3det.openxlab.org.cn/' target='_blank'>Dataset</a></br>
25
+ </strong>
26
+ </div>
27
+ </div>
28
+ </p>
29
+
30
+ <p align="left">
31
+ <img width=960 src="images/introduction.jpg"/>
32
+ </p>
33
+
34
+ ## Codebase
35
+ ### Object Detection
36
+ - [x] mmdetection: https://github.com/V3Det/mmdetection-V3Det/tree/main/configs/v3det
37
+ - [x] Detectron2: https://github.com/V3Det/Detectron2-V3Det
38
+
39
+ ### Open Vocabulary Detection (OVD)
40
+ - [x] Detectron2: https://github.com/V3Det/Detectron2-V3Det
41
+
42
+ ## Data Format
43
+
44
+ The data includes a training set, a validation set, comprising 13,204 categories. The training set consists of 183,354 images, while the validation set has 29,821 images. The data organization is:
45
+ ```
46
+ V3Det/
47
+ images/
48
+ <category_node>/
49
+ |────<image_name>.png
50
+ ...
51
+ ...
52
+ annotations/
53
+ |────v3det_2023_v1_category_tree.json # Category tree
54
+ |────category_name_13204_v3det_2023_v1.txt # Category name
55
+ |────v3det_2023_v1_train.json # Train set
56
+ |────v3det_2023_v1_val.json # Validation set
57
+ ```
58
+
59
+ ## Annotation Files
60
+
61
+ ### Train/Val
62
+ The annotation files are provided in dictionary format and contain the keywords "images," "categories," and "annotations."
63
+
64
+ - images : store a list containing image information, where each element is a dictionary representing an image.
65
+ ```
66
+ file_name # The relative image path, eg. images/n07745046/21_371_29405651261_633d076053_c.jpg.
67
+ height # The height of the image
68
+ width # The width of the image
69
+ id # Unique identifier of the image.
70
+ ```
71
+
72
+ - categories : store a list containing category information, where each element is a dictionary representing a category.
73
+ ```
74
+ name # English name of the category.
75
+ name_zh # Chinese name of the category.
76
+ cat_info # The format for the description information of categories is a list.
77
+ cat_info_gpt # The format for the description information of categories generated by ChatGPT is a list.
78
+ novel # For open-vocabulary detection, indicate whether the current category belongs to the 'novel' category.
79
+ id # Unique identifier of the category.
80
+ ```
81
+
82
+ - annotations : store a list containing annotation information, where each element is a dictionary representing a bounding box annotation.
83
+ ```
84
+ image_id # The unique identifier of the image where the bounding box is located.
85
+ category_id # The unique identifier of the category corresponding to the bounding box.
86
+ bbox # The coordinates of the bounding box, in the format [x, y, w, h], representing the top-left corner coordinates and the width and height of the box.
87
+ iscrowd # Whether the bounding box is a crowd box.
88
+ area # The area of the bounding box
89
+ ```
90
+
91
+ ### Category Tree
92
+ - The category tree stores information about dataset category mappings and relationships in dictionary format.
93
+ ```
94
+ categoryid2treeid # Unique identifier of node in the category tree corresponding to the category identifier in dataset
95
+ id2name # English name corresponding to each node in the category tree
96
+ id2name_zh # Chinese name corresponding to each node in the category tree
97
+ id2desc # English description corresponding to each node in the category tree
98
+ id2desc_zh # Chinese description corresponding to each node in the category tree
99
+ id2synonym_list # List of synonyms corresponding to each node in the category tree
100
+ id2center_synonym # Center synonym corresponding to each node in the category tree
101
+ father2child # All direct child categories corresponding to each node in the category tree
102
+ child2father # All direct parent categories corresponding to each node in the category tree
103
+ ancestor2descendant # All descendant nodes corresponding to each node in the category tree
104
+ descendant2ancestor # All ancestor nodes corresponding to each node in the category tree
105
+ ```
106
+
107
+ ## Image Download
108
+
109
+ - Run the command to crawl the images. By default, the images will be stored in the './V3Det/' directory.
110
+ ```
111
+ python v3det_image_download.py
112
+ ```
113
+ - If you want to change the storage location, you can specify the desired folder by adding the option '--output_folder' when executing the script.
114
+ ```
115
+ python v3det_image_download.py --output_folder our_folder
116
+ ```
117
+
118
+ ## Category Tree Visualization
119
+
120
+ - Run the command and then select dataset path `path/to/V3Det` to visualize the category tree.
121
+ ```
122
+ python v3det_visualize_tree.py
123
+ ```
124
+
125
+ Please refer to the [TreeUI Operation Guide](VisualTree.md) for more information.
126
+
127
+ ## License:
128
+ - **V3Det Images**: Around 90% images in V3Det were selected from the [Bamboo Dataset](https://github.com/ZhangYuanhan-AI/Bamboo), sourced from the Flickr website. The remaining 10% were directly crawled from the Flickr. **We do not own the copyright of the images.** Use of the images must abide by the [Flickr Terms of Use](https://www.flickr.com/creativecommons/). We only provide lists of image URLs without redistribution.
129
+
130
+ - **V3Det Annotations**: The V3Det annotations, the category relationship tree, and related tools are licensed under a [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/) (allow commercial use).
131
+
132
+
133
+ ## Citation
134
+
135
+ ```bibtex
136
+ @inproceedings{wang2023v3det,
137
+ title = {V3Det: Vast Vocabulary Visual Detection Dataset},
138
+ author = {Wang, Jiaqi and Zhang, Pan and Chu, Tao and Cao, Yuhang and Zhou, Yujie and Wu, Tong and Wang, Bin and He, Conghui and Lin, Dahua},
139
+ booktitle = {The IEEE International Conference on Computer Vision (ICCV)},
140
+ month = {October},
141
+ year = {2023}
142
+ }
143
+ ```
VisualTree.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # TreeUI Operation Guide
2
+
3
+ ## Data and Environment Setup
4
+
5
+ Use `v3det_image_download.py` to download the dataset images into `images` in the `/path/to/V3Det` directory.
6
+ Download `v3det_2023_v1_category_tree.json` into the `annotations` directory.
7
+
8
+ Install the required package: `pip install pyqt5`
9
+
10
+ ## Visualization Tool and Instructions
11
+ After running `python v3det_visualize_tree.py`, a dialog box will pop up. Select the downloaded dataset folder `/path/to/V3Det`. Following this, the visualization tool interface will appear:
12
+ ![view.png](images/visual_tree.png)
13
+
14
+ Description of functions and operations:\
15
+ ① Search box: Enter English or Chinese text for searching. The results will be displayed in ⑤.\
16
+ ② Reset button: This is used to reset the search box (①) and the search display area (⑤).\
17
+ ③ Category tree display area: Here you can expand the category tree, select categories, and view the structure and information of the current category in ④, ⑥, and ⑦.\
18
+ ④ Category relationship display area: This shows the relationships of the categories selected in ③/⑤.\
19
+ ⑤ Category search area: Displays the categories searched.\
20
+ ⑥ Category information area: Shows the information of the selected category, including English category name, Chinese category name, English category description, and Chinese category description.\
21
+ ⑦ Image area: Displays related images of the selected category, with a maximum of 16 images displayed at a time.
category_name_13204_v3det_2023_v1.txt ADDED
The diff for this file is too large to render. See raw diff
 
images/introduction.jpg ADDED

Git LFS Details

  • SHA256: a54fbadad18834acc8dedc1f30210195d4906711aa328bc7f91b1663defa108f
  • Pointer size: 131 Bytes
  • Size of remote file: 328 kB
images/v3det_icon.jpg ADDED

Git LFS Details

  • SHA256: f01489a24a472374168885bb70fea341a5c91c4b5ad8c0b05ff3d768337b020b
  • Pointer size: 130 Bytes
  • Size of remote file: 45.5 kB
images/visual_tree.png ADDED

Git LFS Details

  • SHA256: 7579e03d81b7147e211e3d65a5d6c9cbc3bc5918c96bbd46a53e168c3009bbb0
  • Pointer size: 131 Bytes
  • Size of remote file: 312 kB
v3det_image_download.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import argparse
3
+ import concurrent.futures
4
+ import json
5
+ import os
6
+ import time
7
+ import urllib.error
8
+ import urllib.request
9
+
10
+ from tqdm import tqdm
11
+
12
+ parser = argparse.ArgumentParser()
13
+ parser.add_argument("--output_folder", type=str, default="V3Det")
14
+ parser.add_argument("--max_retries", type=int, default=3)
15
+ parser.add_argument("--max_workers", type=int, default=16)
16
+ args = parser.parse_args()
17
+ headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'}
18
+
19
+
20
+ def cache(response):
21
+ f = io.BytesIO()
22
+ block_sz = 8192
23
+ while True:
24
+ buffer = response.read(block_sz)
25
+ if not buffer:
26
+ break
27
+ f.write(buffer)
28
+ return f
29
+
30
+ def download_image(url, path, timeout):
31
+ result = {
32
+ "status": "",
33
+ "url": url,
34
+ "path": path,
35
+ }
36
+ cnt = 0
37
+ while True:
38
+ try:
39
+ response = urllib.request.urlopen(urllib.request.Request(url=url, headers=headers), timeout=timeout)
40
+ image_path = os.path.join(args.output_folder, path)
41
+ os.makedirs(os.path.dirname(image_path), exist_ok=True)
42
+ f = cache(response)
43
+ with open(image_path, "wb") as fp:
44
+ fp.write(f.getvalue())
45
+ result["status"] = "success"
46
+ except Exception as e:
47
+ if not isinstance(e, urllib.error.HTTPError):
48
+ cnt += 1
49
+ if cnt <= args.max_retries:
50
+ continue
51
+ if isinstance(e, urllib.error.HTTPError):
52
+ result["status"] = "expired"
53
+ else:
54
+ result["status"] = "timeout"
55
+ break
56
+ return result
57
+
58
+
59
+ def main():
60
+ start = time.time()
61
+ if os.path.exists(args.output_folder) and os.listdir(args.output_folder):
62
+ try:
63
+ c = input(
64
+ f"'{args.output_folder}' already exists and is not an empty directory, continue? (y/n) "
65
+ )
66
+ if c.lower() not in ["y", "yes"]:
67
+ exit(0)
68
+ except KeyboardInterrupt:
69
+ exit(0)
70
+ if not os.path.exists(args.output_folder):
71
+ os.makedirs(args.output_folder)
72
+ image_folder_path = os.path.join(args.output_folder, "images")
73
+ record_path = os.path.join(args.output_folder, "records.json")
74
+ record = {'success': [], 'expired': [], 'timeout': []}
75
+ if os.path.isfile(record_path):
76
+ try:
77
+ with open(record_path, encoding="utf8") as f:
78
+ record['success'] = json.load(f)['success']
79
+ except:
80
+ pass
81
+ if not os.path.exists(image_folder_path):
82
+ os.makedirs(image_folder_path)
83
+
84
+ list_url = 'https://raw.githubusercontent.com/V3Det/v3det_resource/main/resource/download_list.txt'
85
+ response = urllib.request.urlopen(urllib.request.Request(url=list_url, headers=headers), timeout=10)
86
+ url_list = [url for url in response.read().decode('utf-8').split('\n') if len(url) > 0]
87
+ image2url = {}
88
+ for url in url_list:
89
+ response = urllib.request.urlopen(urllib.request.Request(url=url, headers=headers), timeout=10)
90
+ image2url.update(eval(response.read().decode('utf-8')))
91
+
92
+ data = []
93
+ rec_suc = set(record['success'])
94
+ for image, url in image2url.items():
95
+ if image not in rec_suc:
96
+ data.append((url, image))
97
+ with tqdm(total=len(data)) as pbar:
98
+ with concurrent.futures.ThreadPoolExecutor(max_workers=args.max_workers) as executor:
99
+ # Submit up to `chunk_size` tasks at a time to avoid too many pending tasks.
100
+ chunk_size = min(5000, args.max_workers * 500)
101
+ for i in range(0, len(data), chunk_size):
102
+ futures = [
103
+ executor.submit(download_image, url, path, 10)
104
+ for url, path in data[i: i + chunk_size]
105
+ ]
106
+ for future in concurrent.futures.as_completed(futures):
107
+ r = future.result()
108
+ record[r["status"]].append(r["path"])
109
+ pbar.update(1)
110
+ with open(record_path, "w", encoding="utf8") as f:
111
+ json.dump(record, f, indent=2)
112
+
113
+ end = time.time()
114
+ print(f"consuming time {end - start:.1f} sec")
115
+ print(f"{len(record['success'])} images downloaded.")
116
+ print(f"{len(record['timeout'])} urls failed due to request timeout.")
117
+ print(f"{len(record['expired'])} urls failed due to url expiration.")
118
+ if len(record['success']) == len(image2url):
119
+ os.remove(record_path)
120
+ print('All images have been downloaded!')
121
+ else:
122
+ print('Please run this file again to download failed image!')
123
+
124
+
125
+ if __name__ == "__main__":
126
+ main()
v3det_visualize_tree.py ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import json
4
+ import tkinter
5
+
6
+ from tkinter import filedialog
7
+ from PyQt5 import QtCore, QtGui, QtWidgets
8
+ from PyQt5.QtWidgets import *
9
+ from PyQt5.QtCore import *
10
+ from PyQt5.QtGui import *
11
+ import functools
12
+
13
+ W, H = 800, 800
14
+
15
+ qss = '/*\nMaterial Dark Style Sheet for QT Applications\nAuthor: Jaime A. Quiroga P.\nInspired on https://github.com/jxfwinter/qt-material-stylesheet\nCompany: GTRONICK\nLast updated: 04/12/2018, 15:00.\nAvailable at: https://github.com/GTRONICK/QSS/blob/master/MaterialDark.qss\n*/\nQMainWindow {\n\tbackground-color:#1e1d23;\n\tborder-radius:15px;\n\tfont-family:Segoe UI;\n}\nQDialog {\n\tbackground-color:#1e1d23;\n}\nQColorDialog {\n\tbackground-color:#1e1d23;\n\t\n}\nQTextEdit {\n\tbackground-color:#1e1d23;\n\tcolor: #a9b7c6;\n}\nQPlainTextEdit {\n\tselection-background-color:#007b50;\n\tbackground-color:#1e1d23;\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: transparent;\n\tborder-width: 1px;\n\tcolor: #a9b7c6;\n}\nQPushButton{\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: transparent;\n\tborder-width: 1px;\n\tborder-style: solid;\n\tcolor: #a9b7c6;\n\tpadding: 2px;\n\tbackground-color: #1e1d23;\n\tfont-size: 14px;\n}\nQPushButton::default{\n\tborder-style: inset;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: #04b97f;\n\tborder-width: 1px;\n\tcolor: #a9b7c6;\n\tpadding: 2px;\n\tbackground-color: #1e1d23;\n}\nQToolButton {\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: #04b97f;\n\tborder-bottom-width: 1px;\n\tborder-style: solid;\n\tcolor: #a9b7c6;\n\tpadding: 2px;\n\tbackground-color: #1e1d23;\n}\nQToolButton:hover{\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: #37efba;\n\tborder-bottom-width: 2px;\n\tborder-style: solid;\n\tcolor: #FFFFFF;\n\tpadding-bottom: 1px;\n\tbackground-color: #1e1d23;\n}\nQPushButton:hover{\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: #37efba;\n\tborder-bottom-width: 1px;\n\tborder-style: solid;\n\tcolor: #FFFFFF;\n\tpadding-bottom: 2px;\n\tbackground-color: #1e1d23;\n}\nQPushButton:pressed{\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: #37efba;\n\tborder-bottom-width: 2px;\n\tborder-style: solid;\n\tcolor: #37efba;\n\tpadding-bottom: 1px;\n\tbackground-color: #1e1d23;\n}\nQPushButton:disabled{\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: #808086;\n\tborder-bottom-width: 2px;\n\tborder-style: solid;\n\tcolor: #808086;\n\tpadding-bottom: 1px;\n\tbackground-color: #1e1d23;\n}\nQLineEdit {\n\tborder-width: 1px; border-radius: 4px;\n\tborder-color: rgb(58, 58, 58);\n\tborder-style: inset;\n\tpadding: 0 8px;\n\tcolor: #a9b7c6;\n\tbackground:#1e1d23;\n\tselection-background-color:#007b50;\n\tselection-color: #FFFFFF;\n}\nQLabel {\n\tcolor: #a9b7c6;\n\tfont-size: 14px;\n}\nQLCDNumber {\n\tcolor: #37e6b4;\n}\nQProgressBar {\n\ttext-align: center;\n\tcolor: rgb(240, 240, 240);\n\tborder-width: 1px; \n\tborder-radius: 10px;\n\tborder-color: rgb(58, 58, 58);\n\tborder-style: inset;\n\tbackground-color:#1e1d23;\n}\nQProgressBar::chunk {\n\tbackground-color: #04b97f;\n\tborder-radius: 5px;\n}\nQMenuBar {\n\tbackground-color: #1e1d23;\n}\nQMenuBar::item {\n\tcolor: #a9b7c6;\n \tspacing: 3px;\n \tpadding: 1px 4px;\n \tbackground: #1e1d23;\n}\n\nQMenuBar::item:selected {\n \tbackground:#1e1d23;\n\tcolor: #FFFFFF;\n}\nQMenu::item:selected {\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: #04b97f;\n\tborder-bottom-color: transparent;\n\tborder-left-width: 2px;\n\tcolor: #FFFFFF;\n\tpadding-left:15px;\n\tpadding-top:4px;\n\tpadding-bottom:4px;\n\tpadding-right:7px;\n\tbackground-color: #1e1d23;\n}\nQMenu::item {\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: transparent;\n\tborder-bottom-width: 1px;\n\tborder-style: solid;\n\tcolor: #a9b7c6;\n\tpadding-left:17px;\n\tpadding-top:4px;\n\tpadding-bottom:4px;\n\tpadding-right:7px;\n\tbackground-color: #1e1d23;\n}\nQMenu{\n\tbackground-color:#1e1d23;\n}\nQTabWidget {\n\tcolor:rgb(0,0,0);\n\tbackground-color:#1e1d23;\n}\nQTabWidget::pane {\n\t\tborder-color: rgb(77,77,77);\n\t\tbackground-color:#1e1d23;\n\t\tborder-style: solid;\n\t\tborder-width: 1px;\n \tborder-radius: 6px;\n}\nQTabBar::tab {\n\tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: transparent;\n\tborder-bottom-width: 1px;\n\tborder-style: solid;\n\tcolor: #808086;\n\tpadding: 3px;\n\tmargin-left:3px;\n\tbackground-color: #1e1d23;\n}\nQTabBar::tab:selected, QTabBar::tab:last:selected, QTabBar::tab:hover {\n \tborder-style: solid;\n\tborder-top-color: transparent;\n\tborder-right-color: transparent;\n\tborder-left-color: transparent;\n\tborder-bottom-color: #04b97f;\n\tborder-bottom-width: 2px;\n\tborder-style: solid;\n\tcolor: #FFFFFF;\n\tpadding-left: 3px;\n\tpadding-bottom: 2px;\n\tmargin-left:3px;\n\tbackground-color: #1e1d23;\n}\n\nQCheckBox {\n\tcolor: #a9b7c6;\n\tpadding: 2px;\n}\nQCheckBox:disabled {\n\tcolor: #808086;\n\tpadding: 2px;\n}\n\nQCheckBox:hover {\n\tborder-radius:4px;\n\tborder-style:solid;\n\tpadding-left: 1px;\n\tpadding-right: 1px;\n\tpadding-bottom: 1px;\n\tpadding-top: 1px;\n\tborder-width:1px;\n\tborder-color: rgb(87, 97, 106);\n\tbackground-color:#1e1d23;\n}\nQCheckBox::indicator:checked {\n\n\theight: 10px;\n\twidth: 10px;\n\tborder-style:solid;\n\tborder-width: 1px;\n\tborder-color: #04b97f;\n\tcolor: #a9b7c6;\n\tbackground-color: #04b97f;\n}\nQCheckBox::indicator:unchecked {\n\n\theight: 10px;\n\twidth: 10px;\n\tborder-style:solid;\n\tborder-width: 1px;\n\tborder-color: #04b97f;\n\tcolor: #a9b7c6;\n\tbackground-color: transparent;\n}\nQRadioButton {\n\tcolor: #a9b7c6;\n\tbackground-color: #1e1d23;\n\tpadding: 1px;\n}\nQRadioButton::indicator:checked {\n\theight: 10px;\n\twidth: 10px;\n\tborder-style:solid;\n\tborder-radius:5px;\n\tborder-width: 1px;\n\tborder-color: #04b97f;\n\tcolor: #a9b7c6;\n\tbackground-color: #04b97f;\n}\nQRadioButton::indicator:!checked {\n\theight: 10px;\n\twidth: 10px;\n\tborder-style:solid;\n\tborder-radius:5px;\n\tborder-width: 1px;\n\tborder-color: #04b97f;\n\tcolor: #a9b7c6;\n\tbackground-color: transparent;\n}\nQStatusBar {\n\tcolor:#027f7f;\n}\nQSpinBox {\n\tcolor: #a9b7c6;\t\n\tbackground-color: #1e1d23;\n}\nQDoubleSpinBox {\n\tcolor: #a9b7c6;\t\n\tbackground-color: #1e1d23;\n}\nQTimeEdit {\n\tcolor: #a9b7c6;\t\n\tbackground-color: #1e1d23;\n}\nQDateTimeEdit {\n\tcolor: #a9b7c6;\t\n\tbackground-color: #1e1d23;\n}\nQDateEdit {\n\tcolor: #a9b7c6;\t\n\tbackground-color: #1e1d23;\n}\nQComboBox {\n\tcolor: #a9b7c6;\t\n\tbackground: #1e1d23;\n}\nQComboBox:editable {\n\tbackground: #1e1d23;\n\tcolor: #a9b7c6;\n\tselection-background-color: #1e1d23;\n}\nQComboBox QAbstractItemView {\n\tcolor: #a9b7c6;\t\n\tbackground: #1e1d23;\n\tselection-color: #FFFFFF;\n\tselection-background-color: #1e1d23;\n}\nQComboBox:!editable:on, QComboBox::drop-down:editable:on {\n\tcolor: #a9b7c6;\t\n\tbackground: #1e1d23;\n}\nQFontComboBox {\n\tcolor: #a9b7c6;\t\n\tbackground-color: #1e1d23;\n}\nQToolBox {\n\tcolor: #a9b7c6;\n\tbackground-color: #1e1d23;\n}\nQToolBox::tab {\n\tcolor: #a9b7c6;\n\tbackground-color: #1e1d23;\n}\nQToolBox::tab:selected {\n\tcolor: #FFFFFF;\n\tbackground-color: #1e1d23;\n}\nQScrollArea {\n\tcolor: #FFFFFF;\n\tbackground-color: #1e1d23;\n}\nQSlider::groove:horizontal {\n\theight: 5px;\n\tbackground: #04b97f;\n}\nQSlider::groove:vertical {\n\twidth: 5px;\n\tbackground: #04b97f;\n}\nQSlider::handle:horizontal {\n\tbackground: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);\n\tborder: 0px solid #5c5c5c;\n\twidth: 14px;\n\tmargin: -5px 0;\n\tborder-radius: 7px;\n}\nQSlider::handle:vertical {\n\tbackground: qlineargradient(x1:1, y1:1, x2:0, y2:0, stop:0 #b4b4b4, stop:1 #8f8f8f);\n\tborder: 0px solid #5c5c5c;\n\theight: 14px;\n\tmargin: 0 -5px;\n\tborder-radius: 7px;\n}\nQSlider::add-page:horizontal {\n background: white;\n}\nQSlider::add-page:vertical {\n background: white;\n}\nQSlider::sub-page:horizontal {\n background: #04b97f;\n}\nQSlider::sub-page:vertical {\n background: #04b97f;\n}\n'
16
+
17
+ class MainWindow(QtWidgets.QMainWindow):
18
+ def __init__(self):
19
+ super().__init__()
20
+ self.load_tree()
21
+ self.init_widgets()
22
+ self.init_tree()
23
+
24
+ def load_tree(self):
25
+ self.process_log = []
26
+ root = tkinter.Tk()
27
+ root.withdraw()
28
+ print('Please select the root directory of the V3Det dataset!')
29
+ self.root = filedialog.askdirectory()
30
+ self.tree = {}
31
+ self.visual_cat_list = []
32
+ try:
33
+ with open(os.path.join(self.root, 'annotations', 'v3det_2023_v1_category_tree.json'), encoding='utf-8') as f:
34
+ self.tree = json.load(f)
35
+ self.im_root = os.path.join(self.root, 'images')
36
+ self.visual_cat_list = os.listdir(self.im_root)
37
+ print('Images and category_tree.json are all loaded!')
38
+ except:
39
+ if len(self.tree) == 0:
40
+ print('Error: There is no tree.json!')
41
+ else:
42
+ if len(self.visual_cat_list) == 0:
43
+ print('Warning: There is no images!')
44
+ print('Please make sure the structure of files, and select the root directory:')
45
+ print('| -- V3Det(root)')
46
+ print(' | -- images')
47
+ print(' | -- n00001234')
48
+ print(' | -- ...jpg')
49
+ print(' | -- annotations')
50
+ print(' | -- v3det_2023_v1_category_tree.json')
51
+ if len(self.tree) == 0:
52
+ exit()
53
+
54
+ def init_widgets(self):
55
+ # main layout
56
+ central_widget = QtWidgets.QWidget()
57
+ main_layout = QtWidgets.QHBoxLayout()
58
+ central_widget.setLayout(main_layout)
59
+
60
+ left_layout = QtWidgets.QVBoxLayout()
61
+ search_box = QtWidgets.QHBoxLayout()
62
+ self.search_text = QLineEdit()
63
+ self.search_text.textEdited.connect(self.text_change)
64
+ self.search_button = QPushButton("Search")
65
+ self.search_button.pressed.connect(self.search)
66
+ search_box.addWidget(self.search_text)
67
+ search_box.addWidget(self.search_button)
68
+ left_layout.addLayout(search_box)
69
+
70
+ self.visual_tree = QTreeWidget()
71
+ self.visual_tree.setColumnCount(2)
72
+ self.visual_tree.setHeaderLabels(['name_en', 'name_zh'])
73
+ left_layout.addWidget(self.visual_tree)
74
+
75
+ node_lay = QtWidgets.QHBoxLayout()
76
+ self.current_node = QTreeWidget()
77
+ self.current_node.setColumnCount(2)
78
+ self.current_node.setHeaderLabels(['name_en', 'name_zh'])
79
+ node_lay.addWidget(self.current_node)
80
+
81
+ self.search_list = QTreeWidget()
82
+ self.search_list.setColumnCount(2)
83
+ self.search_list.setHeaderLabels(['name_en', 'name_zh/num'])
84
+ node_lay.addWidget(self.search_list)
85
+ left_layout.addLayout(node_lay)
86
+
87
+ main_layout.addLayout(left_layout)
88
+
89
+ right_layout = QtWidgets.QVBoxLayout()
90
+ info_layout = QtWidgets.QVBoxLayout()
91
+ self.class_id = QLabel("class_id")
92
+ self.class_name_en = QLabel("class_name_en")
93
+ self.class_desc_en = QLabel("class_desc_en")
94
+ self.class_name_zh = QLabel("class_name_zh")
95
+ self.class_desc_zh = QLabel("class_desc_zh")
96
+ self.class_id.setTextInteractionFlags(Qt.TextSelectableByMouse)
97
+ self.class_name_en.setTextInteractionFlags(Qt.TextSelectableByMouse)
98
+ self.class_name_en.setWordWrap(True)
99
+ self.class_desc_en.setTextInteractionFlags(Qt.TextSelectableByMouse)
100
+ self.class_desc_en.setWordWrap(True)
101
+ self.class_name_zh.setTextInteractionFlags(Qt.TextSelectableByMouse)
102
+ self.class_name_zh.setWordWrap(True)
103
+ self.class_desc_zh.setTextInteractionFlags(Qt.TextSelectableByMouse)
104
+ self.class_desc_zh.setWordWrap(True)
105
+ self.class_name_en.setFixedWidth(W)
106
+ self.class_desc_en.setFixedWidth(W)
107
+ self.class_name_zh.setFixedWidth(W)
108
+ self.class_desc_zh.setFixedWidth(W)
109
+ info_layout.addWidget(self.class_id, QtCore.Qt.AlignLeft)
110
+ info_layout.addWidget(self.class_name_en, QtCore.Qt.AlignLeft)
111
+ info_layout.addWidget(self.class_name_zh, QtCore.Qt.AlignLeft)
112
+ info_layout.addWidget(self.class_desc_en, QtCore.Qt.AlignLeft)
113
+ info_layout.addWidget(self.class_desc_zh, QtCore.Qt.AlignLeft)
114
+ right_layout.addLayout(info_layout)
115
+
116
+ self.class_images = []
117
+ num_items = 4
118
+ for num_im_i in range(num_items):
119
+ img_layout = QtWidgets.QHBoxLayout()
120
+ for num_im_j in range(num_items):
121
+ image = CanvasImage(1 / num_items)
122
+ self.class_images.append(image)
123
+ img_layout.addWidget(image)
124
+ right_layout.addLayout(img_layout)
125
+
126
+ main_layout.addLayout(right_layout)
127
+
128
+ self.setCentralWidget(central_widget)
129
+ self.setWindowIcon(QIcon('icon.png'))
130
+ self.setStyleSheet(qss)
131
+
132
+ self.visual_tree.itemClicked.connect(
133
+ functools.partial(self.onitemSelectionChanged, self.visual_tree))
134
+ self.current_node.itemClicked.connect(
135
+ functools.partial(self.onitemSelectionChanged, self.current_node))
136
+ self.search_list.itemClicked.connect(
137
+ functools.partial(self.onitemSelectionChanged, self.search_list))
138
+
139
+ self.visual_tree.itemSelectionChanged.connect(
140
+ functools.partial(self.onitemSelectionChanged, self.visual_tree))
141
+ self.current_node.itemSelectionChanged.connect(
142
+ functools.partial(self.onitemSelectionChanged, self.current_node))
143
+ self.search_list.itemSelectionChanged.connect(
144
+ functools.partial(self.onitemSelectionChanged, self.search_list))
145
+
146
+ self.visual_tree.itemDoubleClicked.connect(
147
+ functools.partial(self.onitemSelectionChanged, self.visual_tree))
148
+ self.current_node.itemDoubleClicked.connect(
149
+ functools.partial(self.onitemSelectionChanged, self.current_node))
150
+ self.search_list.itemDoubleClicked.connect(
151
+ functools.partial(self.onitemSelectionChanged, self.search_list))
152
+
153
+ def init_tree(self):
154
+ child_num = {}
155
+
156
+ def count_child(node):
157
+ num = 1
158
+ if node in self.tree['father2child']:
159
+ for child in self.tree['father2child'][node]:
160
+ num += count_child(child)
161
+ child_num[node] = num
162
+ return num
163
+ count_child('n00001740')
164
+ self.child_num = child_num
165
+
166
+ self.show_tree()
167
+
168
+ def show_tree(self, node='n00001740', level=0, parent=None):
169
+ name_en = self.tree['id2name'][node]
170
+ name_en = name_en + '({})'.format(self.child_num[node])
171
+ name_zh = str(self.tree['id2name_zh'][node]) if node in self.tree['id2name_zh'] else ''
172
+ current = QtWidgets.QTreeWidgetItem(["{}-{}".format(level, name_en), name_zh])
173
+
174
+ current.id = node
175
+ if node == 'n00001740':
176
+ self.visual_tree.addTopLevelItem(current)
177
+ else:
178
+ parent.addChild(current)
179
+ if node in self.tree['father2child']:
180
+ for child in self.tree['father2child'][node]:
181
+ self.show_tree(child, level + 1, current)
182
+
183
+ def text_change(self):
184
+ if self.search_button.text() == 'Reset':
185
+ self.search(False)
186
+ if len(self.search_text.text().encode('utf-8')) > 1:
187
+ self.search(False)
188
+
189
+ def search(self, text_reset=True):
190
+ if self.search_button.text() == 'Search':
191
+ text = self.search_text.text()
192
+ if len(text) != 0:
193
+ searched_list = [class_id for class_id in self.tree['id2name'].keys() if class_id == text]
194
+ for item in ['id2name', 'id2name_zh', 'id2desc', 'id2desc_zh']:
195
+ for k, v in self.tree[item].items():
196
+ if k not in self.tree.get('child2father'):
197
+ continue
198
+ if isinstance(v, list):
199
+ names = ''
200
+ for vi in v:
201
+ names += vi
202
+ v = names
203
+ if isinstance(v, str):
204
+ if (k not in searched_list) and (text.lower() in v.lower()):
205
+ if k in self.tree['id2name']:
206
+ searched_list.append(k)
207
+
208
+ self.insert_num = len(searched_list)
209
+ self.show_list(searched_list)
210
+
211
+ self.search_button.setText('Reset')
212
+
213
+ elif self.search_button.text() == 'Reset':
214
+ self.search_list.clear()
215
+ self.insert_num = 0
216
+ if text_reset:
217
+ self.search_text.setText('')
218
+ self.search_button.setText('Search')
219
+
220
+ def show_list(self, show_list, insert_index=-1):
221
+ num_id = 0
222
+ for cat_id in show_list:
223
+ if len(cat_id) == 0:
224
+ continue
225
+ num_id += 1
226
+ name_en = self.tree['id2name'][cat_id] if len(self.tree['id2name'][cat_id]) else ''
227
+ name_en = name_en + '({})'.format(len(self.tree['ancestor2descendant'].get(cat_id, set())))
228
+ name_zh = self.tree['id2name_zh'].get(cat_id, '')
229
+ cur = QtWidgets.QTreeWidgetItem(["{}-{}".format(num_id, name_en), name_zh])
230
+ cur.id = cat_id
231
+
232
+ insert_id = insert_index if insert_index >= 0 else self.search_list.topLevelItemCount()
233
+ self.search_list.insertTopLevelItem(insert_id, cur)
234
+
235
+ def onItemClicked(self, class_id):
236
+ self.class_id.setText(class_id)
237
+ self.class_name_en.setText(self.tree['id2name'][class_id])
238
+ self.class_desc_en.setText(self.tree['id2desc'].get(class_id, ''))
239
+ self.class_name_zh.setText(self.tree['id2name_zh'].get(class_id, ''))
240
+ self.class_desc_zh.setText(self.tree['id2desc_zh'].get(class_id, ''))
241
+
242
+ [im.clean() for im in self.class_images]
243
+ if class_id in self.visual_cat_list:
244
+ show_num = len(self.class_images)
245
+ folder = os.path.join(self.im_root, class_id)
246
+ im_names = os.listdir(folder)
247
+ num_image = 0
248
+ for im_i in im_names:
249
+ if num_image == show_num:
250
+ break
251
+ self.class_images[num_image].load_image(os.path.join(folder, im_i))
252
+ num_image += 1
253
+
254
+ self.add_current(class_id)
255
+
256
+ def add_current(self, class_id):
257
+ name_en = self.tree['id2name'][class_id]
258
+ name_en = name_en + '({})'.format(len(self.tree['ancestor2descendant'].get(class_id, set())))
259
+ name_zh = self.tree['id2name_zh'].get(class_id, '')
260
+ self.current_node.clear()
261
+ current = QtWidgets.QTreeWidgetItem([name_en, name_zh])
262
+ current.id = class_id
263
+
264
+ self.current_node.addTopLevelItem(current)
265
+ for relation in ['father2child', 'child2father', 'id2synonym_list', 'ancestor2descendant', 'descendant2ancestor']:
266
+ rel = QtWidgets.QTreeWidgetItem([relation, str(len(self.tree[relation].get(class_id, [])))])
267
+ current.addChild(rel)
268
+ for rel_class in self.tree[relation].get(class_id, []):
269
+ name_en = self.tree['id2name'][rel_class]
270
+ name_en = name_en + '({})'.format(
271
+ len(self.tree['ancestor2descendant'].get(rel_class, set())))
272
+ name_zh = self.tree['id2name_zh'].get(rel_class, '')
273
+ rel_node = QtWidgets.QTreeWidgetItem([name_en, name_zh])
274
+ rel_node.id = rel_class
275
+ rel.addChild(rel_node)
276
+ self.current_node.expandAll()
277
+
278
+ def onitemSelectionChanged(self, node_tree):
279
+ if node_tree.selectedItems():
280
+ if hasattr(node_tree.selectedItems()[0], 'id'):
281
+ self.onItemClicked(node_tree.selectedItems()[0].id)
282
+
283
+ def keyPressEvent(self, qKeyEvent):
284
+ super().keyPressEvent(qKeyEvent)
285
+
286
+
287
+ class CanvasImage(QtWidgets.QLabel):
288
+ def __init__(self, scale=1.):
289
+ super().__init__()
290
+ self.save_root = 'select'
291
+ self.scale = scale
292
+ self.clean()
293
+
294
+ def load_image(self, path):
295
+ pixmap = QPixmap(path)
296
+ w, h = pixmap.width(), pixmap.height()
297
+ r = min(self.scale * W / w, self.scale * H / h)
298
+ w, h = int(r * w), int(r * h)
299
+ pixmap = pixmap.scaled(w, h, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
300
+
301
+ self.setAlignment(Qt.AlignCenter | Qt.AlignCenter)
302
+ self.setPixmap(pixmap)
303
+
304
+ def clean(self):
305
+ pixmap = QtGui.QPixmap(int(W * self.scale), int(H * self.scale))
306
+ pixmap.fill(QColor("white"))
307
+ self.setPixmap(pixmap)
308
+
309
+
310
+ if __name__ == '__main__':
311
+ app = QtWidgets.QApplication(sys.argv)
312
+ app.setStyle('Material')
313
+ window = MainWindow()
314
+ window.show()
315
+ app.exec_()
316
+