semaj83 commited on
Commit
b09c7b1
1 Parent(s): b179dbf

Upload 3 files

Browse files
Files changed (3) hide show
  1. coco_classes.txt +80 -0
  2. create_prompts.py +109 -0
  3. mini_prompts.txt +0 -0
coco_classes.txt ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ person
2
+ bicycle
3
+ car
4
+ motorcycle
5
+ airplane
6
+ bus
7
+ train
8
+ truck
9
+ boat
10
+ traffic light
11
+ fire hydrant
12
+ stop sign
13
+ parking meter
14
+ bench
15
+ bird
16
+ cat
17
+ dog
18
+ horse
19
+ sheep
20
+ cow
21
+ elephant
22
+ bear
23
+ zebra
24
+ giraffe
25
+ backpack
26
+ umbrella
27
+ handbag
28
+ tie
29
+ suitcase
30
+ frisbee
31
+ skis
32
+ snowboard
33
+ sports ball
34
+ kite
35
+ baseball bat
36
+ baseball glove
37
+ skateboard
38
+ surfboard
39
+ tennis racket
40
+ bottle
41
+ wine glass
42
+ cup
43
+ fork
44
+ knife
45
+ spoon
46
+ bowl
47
+ banana
48
+ apple
49
+ sandwich
50
+ orange
51
+ broccoli
52
+ carrot
53
+ hot dog
54
+ pizza
55
+ donut
56
+ cake
57
+ chair
58
+ couch
59
+ potted plant
60
+ bed
61
+ dining table
62
+ toilet
63
+ tv
64
+ laptop
65
+ mouse
66
+ remote
67
+ keyboard
68
+ cell phone
69
+ microwave
70
+ oven
71
+ toaster
72
+ sink
73
+ refrigerator
74
+ book
75
+ clock
76
+ vase
77
+ scissors
78
+ teddy bear
79
+ hair drier
80
+ toothbrush
create_prompts.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from itertools import combinations, permutations
3
+ from pathlib import Path
4
+ from typing import List
5
+ import random
6
+
7
+ SAVE_PATH = "prompts.txt"
8
+ MINI_SAVE_PATH = "mini_prompts.txt"
9
+
10
+ # COCO Classes, from https://docs.ultralytics.com/datasets/detect/coco/#dataset-yaml
11
+ OBJECT_PATH = Path(__file__).parent / "coco_classes.txt"
12
+
13
+ MAX_IMG_OBJECTS = 3
14
+ MAX_OBJ_QUANTITY = 5
15
+
16
+
17
+
18
+ def get_objects() -> List[str]:
19
+ with open(OBJECT_PATH) as f:
20
+ objects = [o.strip('\n') for o in f.readlines()]
21
+ return objects
22
+
23
+
24
+ def get_plural_suffix(object: str) -> str:
25
+ suffix = ""
26
+ if object == "person":
27
+ object = "people"
28
+
29
+ elif object.endswith("s") or object.endswith("sh") or object.endswith("ch"):
30
+ suffix = "es"
31
+
32
+ elif object.endswith("y"):
33
+ suffix = "ies"
34
+ object = object[:-1]
35
+
36
+ else:
37
+ suffix = "s"
38
+
39
+ object += suffix
40
+ return object
41
+
42
+
43
+
44
+ def gen_prompt_quantifier_helper(object: str, n: int) -> str:
45
+ """
46
+ object: str, ex: 'person', 'car', 'dog', etc.
47
+ returns: list of object strings with quantifier prefix and pluralization
48
+ """
49
+ if n > 1:
50
+ object = get_plural_suffix(object)
51
+
52
+ return f"{n} {object}"
53
+
54
+
55
+
56
+ def gen_single_object_prompts(objects: List[str]) -> List[str]:
57
+ prompts = []
58
+ for obj in objects:
59
+ prompts.extend(gen_prompt_quantifier_helper(obj))
60
+ return prompts
61
+
62
+ def generate_prompts(objects):
63
+ """
64
+ Generates a list of prompts and saves them for model evaluation
65
+ e.g.
66
+ 1 person
67
+ 2 people
68
+ 3 people
69
+ 1 person and 1 car
70
+ 2 people and 1 car
71
+ 3 people and 1 car
72
+ 1 person and 2 cars
73
+ 2 people and 2 cars
74
+ 3 people and 2 cars
75
+ ...
76
+ """
77
+ prompts = set()
78
+ for num_img_objects in range(1, MAX_IMG_OBJECTS + 1):
79
+ for combo in combinations(objects, num_img_objects):
80
+ for count_permute in permutations(list(range(1, MAX_OBJ_QUANTITY + 1)) * num_img_objects, num_img_objects):
81
+ prompt = ""
82
+ for i, obj in enumerate(combo):
83
+ if i > 0:
84
+ prompt += " and "
85
+ prompt += gen_prompt_quantifier_helper(obj, count_permute[i])
86
+
87
+ prompts.add(prompt)
88
+
89
+ return prompts
90
+
91
+
92
+ def save_prompts(prompts: List[str], save_path: str = SAVE_PATH):
93
+ with open(save_path, 'w') as f:
94
+ for prompt in prompts:
95
+ f.write(prompt + '\n')
96
+
97
+
98
+
99
+
100
+
101
+ if __name__ == "__main__":
102
+ objects = get_objects()
103
+ prompts = sorted(list(generate_prompts(objects)))
104
+ save_prompts(prompts)
105
+
106
+ # mini_objects = random.sample(objects, 10)
107
+ # prompts = sorted(list(generate_prompts(mini_objects)))
108
+ # save_prompts(prompts, MINI_SAVE_PATH)
109
+
mini_prompts.txt ADDED
The diff for this file is too large to render. See raw diff