From 3e954fa828f64d40f49f67fefb38d809458a42be Mon Sep 17 00:00:00 2001 From: ferdinandl007 Date: Sat, 24 Apr 2021 21:10:30 +0200 Subject: [PATCH 1/6] add object365 --- data/hyp.finetune_object365.yaml | 28 ++++++++++++ data/object365.yaml | 75 ++++++++++++++++++++++++++++++++ data/scripts/coco-to-yolo.py | 0 data/scripts/datasplit.py | 0 4 files changed, 103 insertions(+) create mode 100644 data/hyp.finetune_object365.yaml create mode 100644 data/object365.yaml create mode 100644 data/scripts/coco-to-yolo.py create mode 100644 data/scripts/datasplit.py diff --git a/data/hyp.finetune_object365.yaml b/data/hyp.finetune_object365.yaml new file mode 100644 index 000000000000..2b104ef2d9bf --- /dev/null +++ b/data/hyp.finetune_object365.yaml @@ -0,0 +1,28 @@ +lr0: 0.00258 +lrf: 0.17 +momentum: 0.779 +weight_decay: 0.00058 +warmup_epochs: 1.33 +warmup_momentum: 0.86 +warmup_bias_lr: 0.0711 +box: 0.0539 +cls: 0.299 +cls_pw: 0.825 +obj: 0.632 +obj_pw: 1.0 +iou_t: 0.2 +anchor_t: 3.44 +anchors: 3.2 +fl_gamma: 0.0 +hsv_h: 0.0188 +hsv_s: 0.704 +hsv_v: 0.36 +degrees: 0.0 +translate: 0.0902 +scale: 0.491 +shear: 0.0 +perspective: 0.0 +flipud: 0.0 +fliplr: 0.5 +mosaic: 1.0 +mixup: 0.0 diff --git a/data/object365.yaml b/data/object365.yaml new file mode 100644 index 000000000000..c89c2ce3d317 --- /dev/null +++ b/data/object365.yaml @@ -0,0 +1,75 @@ +# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] +train: ../dataset/object365/images/train/ # 1.7 Million images +val: ../dataset/object365/images/val/ # 5570 images +# number of classes +nc: 365 + +# class names +names: ['Person', 'Sneakers', 'Chair', 'Other Shoes', 'Hat', 'Car', 'Lamp', + 'Glasses', 'Bottle', 'Desk', 'Cup', 'Street Lights', 'Cabinet/shelf', + 'Handbag/Satchel', 'Bracelet', 'Plate', 'Picture/Frame', 'Helmet', + 'Book', 'Gloves', 'Storage box', 'Boat', 'Leather Shoes', 'Flower', + 'Bench', 'Potted Plant', 'Bowl/Basin', 'Flag', 'Pillow', 'Boots', + 'Vase', 'Microphone', 'Necklace', 'Ring', 'SUV', 'Wine Glass', + 'Belt', 'Moniter/TV', 'Backpack', 'Umbrella', 'Traffic Light', + 'Speaker', 'Watch', 'Tie', 'Trash bin Can', 'Slippers', 'Bicycle', + 'Stool', 'Barrel/bucket', 'Van', 'Couch', 'Sandals', 'Bakset', 'Drum', + 'Pen/Pencil', 'Bus', 'Wild Bird', 'High Heels', 'Motorcycle', 'Guitar', + 'Carpet', 'Cell Phone', 'Bread', 'Camera', 'Canned', 'Truck', + 'Traffic cone', 'Cymbal', 'Lifesaver', 'Towel', 'Stuffed Toy', + 'Candle', 'Sailboat', 'Laptop', 'Awning', 'Bed', 'Faucet', 'Tent', + 'Horse', 'Mirror', 'Power outlet', 'Sink', 'Apple', 'Air Conditioner', + 'Knife', 'Hockey Stick', 'Paddle', 'Pickup Truck', 'Fork', + 'Traffic Sign', 'Ballon', 'Tripod', 'Dog', 'Spoon', 'Clock', + 'Pot', 'Cow', 'Cake', 'Dinning Table', 'Sheep', 'Hanger', + 'Blackboard/Whiteboard', 'Napkin', 'Other Fish', 'Orange/Tangerine', + 'Toiletry', 'Keyboard', 'Tomato', 'Lantern', 'Machinery Vehicle', + 'Fan', 'Green Vegetables', 'Banana', 'Baseball Glove', 'Airplane', + 'Mouse', 'Train', 'Pumpkin', 'Soccer', 'Skiboard', 'Luggage', + 'Nightstand', 'Tea pot', 'Telephone', 'Trolley', 'Head Phone', + 'Sports Car', 'Stop Sign', 'Dessert', 'Scooter', 'Stroller', 'Crane', + 'Remote', 'Refrigerator', 'Oven', 'Lemon', 'Duck', 'Baseball Bat', + 'Surveillance Camera', 'Cat', 'Jug', 'Broccoli', 'Piano', 'Pizza', + 'Elephant', 'Skateboard', 'Surfboard', 'Gun', 'Skating and Skiing shoes', + 'Gas stove', 'Donut', 'Bow Tie', 'Carrot', 'Toilet', 'Kite', + 'Strawberry', 'Other Balls', 'Shovel', 'Pepper', 'Computer Box', + 'Toilet Paper', 'Cleaning Products', 'Chopsticks', 'Microwave', + 'Pigeon', 'Baseball', 'Cutting/chopping Board', 'Coffee Table', + 'Side Table', 'Scissors', 'Marker', 'Pie', 'Ladder', 'Snowboard', + 'Cookies', 'Radiator', 'Fire Hydrant', 'Basketball', 'Zebra', + 'Grape', 'Giraffe', 'Potato', 'Sausage', 'Tricycle', 'Violin', + 'Egg', 'Fire Extinguisher', 'Candy', 'Fire Truck', 'Billards', + 'Converter', 'Bathtub', 'Wheelchair', 'Golf Club', 'Briefcase', + 'Cucumber', 'Cigar/Cigarette ', 'Paint Brush', 'Pear', 'Heavy Truck', + 'Hamburger', 'Extractor', 'Extention Cord', 'Tong', 'Tennis Racket', + 'Folder', 'American Football', 'earphone', 'Mask', 'Kettle', + 'Tennis', 'Ship', 'Swing', 'Coffee Machine', 'Slide', 'Carriage', + 'Onion', 'Green beans', 'Projector', 'Frisbee', + 'Washing Machine/Drying Machine', 'Chicken', 'Printer', 'Watermelon', + 'Saxophone', 'Tissue', 'Toothbrush', 'Ice cream', 'Hotair ballon', + 'Cello', 'French Fries', 'Scale', 'Trophy', 'Cabbage', 'Hot dog', + 'Blender', 'Peach', 'Rice', 'Wallet/Purse', 'Volleyball', 'Deer', + 'Goose', 'Tape', 'Tablet', 'Cosmetics', 'Trumpet', 'Pineapple', + 'Golf Ball', 'Ambulance', 'Parking meter', 'Mango', 'Key', + 'Hurdle', 'Fishing Rod', 'Medal', 'Flute', 'Brush', 'Penguin', + 'Megaphone', 'Corn', 'Lettuce', 'Garlic', 'Swan', 'Helicopter', + 'Green Onion', 'Sandwich', 'Nuts', 'Speed Limit Sign', + 'Induction Cooker', 'Broom', 'Trombone', 'Plum', 'Rickshaw', + 'Goldfish', 'Kiwi fruit', 'Router/modem', 'Poker Card', 'Toaster', + 'Shrimp', 'Sushi', 'Cheese', 'Notepaper', 'Cherry', 'Pliers', 'CD', + 'Pasta', 'Hammer', 'Cue', 'Avocado', 'Hamimelon', 'Flask', 'Mushroon', + 'Screwdriver', 'Soap', 'Recorder', 'Bear', 'Eggplant', 'Board Eraser', + 'Coconut', 'Tape Measur/ Ruler', 'Pig', 'Showerhead', 'Globe', + 'Chips', 'Steak', 'Crosswalk Sign', 'Stapler', 'Campel', 'Formula 1 ', + 'Pomegranate', 'Dishwasher', 'Crab', 'Hoverboard', 'Meat ball', + 'Rice Cooker', 'Tuba', 'Calculator', 'Papaya', 'Antelope', 'Parrot', + 'Seal', 'Buttefly', 'Dumbbell', 'Donkey', 'Lion', 'Urinal', 'Dolphin', + 'Electric Drill', 'Hair Dryer', 'Egg tart', 'Jellyfish', 'Treadmill', + 'Lighter', 'Grapefruit', 'Game board', 'Mop', 'Radish', 'Baozi', + 'Target', 'French', 'Spring Rolls', 'Monkey', 'Rabbit', 'Pencil Case', + 'Yak', 'Red Cabbage', 'Binoculars', 'Asparagus', 'Barbell', 'Scallop', + 'Noddles', 'Comb', 'Dumpling', 'Oyster', 'Table Teniis paddle', + 'Cosmetics Brush/Eyeliner Pencil', 'Chainsaw', 'Eraser', 'Lobster', + 'Durian', 'Okra', 'Lipstick', 'Cosmetics Mirror', 'Curling', + 'Table Tennis'] + diff --git a/data/scripts/coco-to-yolo.py b/data/scripts/coco-to-yolo.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/data/scripts/datasplit.py b/data/scripts/datasplit.py new file mode 100644 index 000000000000..e69de29bb2d1 From ceba623b73ddd241a33ebd878247f93f0879acf9 Mon Sep 17 00:00:00 2001 From: ferdinandl007 Date: Sat, 24 Apr 2021 21:19:04 +0200 Subject: [PATCH 2/6] ADD CONVERSION SCRIPT --- data/scripts/coco-to-yolo.py | 80 ++++++++++++++++++++++++++++++++++++ data/scripts/datasplit.py | 0 2 files changed, 80 insertions(+) delete mode 100644 data/scripts/datasplit.py diff --git a/data/scripts/coco-to-yolo.py b/data/scripts/coco-to-yolo.py index e69de29bb2d1..e0fb12ddaef4 100644 --- a/data/scripts/coco-to-yolo.py +++ b/data/scripts/coco-to-yolo.py @@ -0,0 +1,80 @@ +from pycocotools.coco import COCO +import cv2 +import numpy as np +import glob +import shutil + +# Truncates numbers to N decimals +def truncate(n, decimals=0): + multiplier = 10 ** decimals + return int(n * multiplier) / multiplier + + +# Download Object 365 from the Object 365 website and put in the same directory as this script +coco = COCO("instances_train.json") +cats = coco.loadCats(coco.getCatIds()) +nms = [cat["name"] for cat in cats] +print("COCO categories: \n{}\n".format(" ".join(nms))) +cash = set() + +for categoryId, cat in enumerate(nms): + catIds = coco.getCatIds(catNms=[cat]) + imgIds = coco.getImgIds(catIds=catIds) + images = coco.loadImgs(imgIds) + print(cat) + # # Create a subfolder in this directory called "labels". This is where the annotations will be saved in YOLO format + for im in images: + dw = 1.0 / im["width"] + dh = 1.0 / im["height"] + + annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None) + anns = coco.loadAnns(annIds) + + path = im["file_name"].split("/") + fixed_path = path[-1] + filename = fixed_path.replace(".jpg", ".txt") + + try: + # Test image for corruption + if fixed_path not in cash: + img = cv2.imread(f"images/train/{fixed_path}") + img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + cash.add(fixed_path) + + with open("/labels/train/" + filename, "a+") as myfile: + for i in range(len(anns)): + xmin = anns[i]["bbox"][0] + ymin = anns[i]["bbox"][1] + xmax = anns[i]["bbox"][2] + anns[i]["bbox"][0] + ymax = anns[i]["bbox"][3] + anns[i]["bbox"][1] + + x = (xmin + xmax) / 2 + y = (ymin + ymax) / 2 + + w = xmax - xmin + h = ymax - ymin + + x = x * dw + w = w * dw + y = y * dh + h = h * dh + + # Note: This assumes a single-category dataset, and thus the "0" at the beginning of each line. + mystring = f"{categoryId} {truncate(x, 7)} {truncate(y, 7)} {truncate(w, 7)} {truncate(h, 7)}" + # mystring = str(categoryId + " " + str(truncate(x, 7)) + " " + str(truncate(y, 7)) + " " + str(truncate(w, 7)) + " " + str(truncate(h, 7))) + myfile.write(mystring) + myfile.write("\n") + myfile.close() + + except Exception as e: + print(e) + +current_dir = "images/train" +myset = {2, 25, 4, 5} +for fullpath in glob.iglob(os.path.join(current_dir, "*.jpg")): + n = random.randint(1, 100) + if n in myset: + title, ext = os.path.splitext(os.path.basename(fullpath)) + print(title) + shutil.move(f"../images/train/{title}.jpg", f"../images/val/{title}.jpg") + shutil.move(f"../labels/train/{title}.txt", f"../labels/val/{title}.txt") diff --git a/data/scripts/datasplit.py b/data/scripts/datasplit.py deleted file mode 100644 index e69de29bb2d1..000000000000 From 2a2e412bf0097024dfefdb1eeaabf7abecbe44fd Mon Sep 17 00:00:00 2001 From: ferdinandl007 Date: Mon, 26 Apr 2021 10:41:58 +0200 Subject: [PATCH 3/6] fix transcript --- ...to-yolo.py => object365-to-yolo-format.py} | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) rename data/scripts/{coco-to-yolo.py => object365-to-yolo-format.py} (76%) diff --git a/data/scripts/coco-to-yolo.py b/data/scripts/object365-to-yolo-format.py similarity index 76% rename from data/scripts/coco-to-yolo.py rename to data/scripts/object365-to-yolo-format.py index e0fb12ddaef4..e5ac7c9f8578 100644 --- a/data/scripts/coco-to-yolo.py +++ b/data/scripts/object365-to-yolo-format.py @@ -10,8 +10,13 @@ def truncate(n, decimals=0): return int(n * multiplier) / multiplier -# Download Object 365 from the Object 365 website and put in the same directory as this script -coco = COCO("instances_train.json") +# Create the following folder structure dataset/object365/images/train, dataset/object365/images/val, dataset/labels/images/train, dataset/labels/images/val + +# Download Object 365 from the Object 365 website And unpack all images in dataset/object365/images/train,Put The script and zhiyuan_objv2_train.json file in dataset/object365 +# Execute the script in dataset/object365v path + + +coco = COCO("zhiyuan_objv2_train.json") cats = coco.loadCats(coco.getCatIds()) nms = [cat["name"] for cat in cats] print("COCO categories: \n{}\n".format(" ".join(nms))) @@ -35,13 +40,13 @@ def truncate(n, decimals=0): filename = fixed_path.replace(".jpg", ".txt") try: - # Test image for corruption + # Test image for missing images if fixed_path not in cash: img = cv2.imread(f"images/train/{fixed_path}") img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) cash.add(fixed_path) - with open("/labels/train/" + filename, "a+") as myfile: + with open("labels/train/" + filename, "a+") as myfile: for i in range(len(anns)): xmin = anns[i]["bbox"][0] ymin = anns[i]["bbox"][1] @@ -61,7 +66,6 @@ def truncate(n, decimals=0): # Note: This assumes a single-category dataset, and thus the "0" at the beginning of each line. mystring = f"{categoryId} {truncate(x, 7)} {truncate(y, 7)} {truncate(w, 7)} {truncate(h, 7)}" - # mystring = str(categoryId + " " + str(truncate(x, 7)) + " " + str(truncate(y, 7)) + " " + str(truncate(w, 7)) + " " + str(truncate(h, 7))) myfile.write(mystring) myfile.write("\n") myfile.close() @@ -70,11 +74,11 @@ def truncate(n, decimals=0): print(e) current_dir = "images/train" -myset = {2, 25, 4, 5} +chances = 10 # 10% val set for fullpath in glob.iglob(os.path.join(current_dir, "*.jpg")): n = random.randint(1, 100) - if n in myset: + if n <= chances: title, ext = os.path.splitext(os.path.basename(fullpath)) print(title) - shutil.move(f"../images/train/{title}.jpg", f"../images/val/{title}.jpg") - shutil.move(f"../labels/train/{title}.txt", f"../labels/val/{title}.txt") + shutil.move(f"images/train/{title}.jpg", f"images/val/{title}.jpg") + shutil.move(f"labels/train/{title}.txt", f"labels/val/{title}.txt") From 9c71d6f582a8e9ee96785c81b35ae7a02856bce2 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 28 Apr 2021 23:53:01 +0200 Subject: [PATCH 4/6] Reformat and simplify --- ...t365.yaml => hyp.finetune_objects365.yaml} | 0 data/object365.yaml | 75 ----------------- data/objects365.yaml | 57 +++++++++++++ data/scripts/get_objects365.py | 38 +++++++++ data/scripts/object365-to-yolo-format.py | 84 ------------------- 5 files changed, 95 insertions(+), 159 deletions(-) rename data/{hyp.finetune_object365.yaml => hyp.finetune_objects365.yaml} (100%) delete mode 100644 data/object365.yaml create mode 100644 data/objects365.yaml create mode 100644 data/scripts/get_objects365.py delete mode 100644 data/scripts/object365-to-yolo-format.py diff --git a/data/hyp.finetune_object365.yaml b/data/hyp.finetune_objects365.yaml similarity index 100% rename from data/hyp.finetune_object365.yaml rename to data/hyp.finetune_objects365.yaml diff --git a/data/object365.yaml b/data/object365.yaml deleted file mode 100644 index c89c2ce3d317..000000000000 --- a/data/object365.yaml +++ /dev/null @@ -1,75 +0,0 @@ -# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] -train: ../dataset/object365/images/train/ # 1.7 Million images -val: ../dataset/object365/images/val/ # 5570 images -# number of classes -nc: 365 - -# class names -names: ['Person', 'Sneakers', 'Chair', 'Other Shoes', 'Hat', 'Car', 'Lamp', - 'Glasses', 'Bottle', 'Desk', 'Cup', 'Street Lights', 'Cabinet/shelf', - 'Handbag/Satchel', 'Bracelet', 'Plate', 'Picture/Frame', 'Helmet', - 'Book', 'Gloves', 'Storage box', 'Boat', 'Leather Shoes', 'Flower', - 'Bench', 'Potted Plant', 'Bowl/Basin', 'Flag', 'Pillow', 'Boots', - 'Vase', 'Microphone', 'Necklace', 'Ring', 'SUV', 'Wine Glass', - 'Belt', 'Moniter/TV', 'Backpack', 'Umbrella', 'Traffic Light', - 'Speaker', 'Watch', 'Tie', 'Trash bin Can', 'Slippers', 'Bicycle', - 'Stool', 'Barrel/bucket', 'Van', 'Couch', 'Sandals', 'Bakset', 'Drum', - 'Pen/Pencil', 'Bus', 'Wild Bird', 'High Heels', 'Motorcycle', 'Guitar', - 'Carpet', 'Cell Phone', 'Bread', 'Camera', 'Canned', 'Truck', - 'Traffic cone', 'Cymbal', 'Lifesaver', 'Towel', 'Stuffed Toy', - 'Candle', 'Sailboat', 'Laptop', 'Awning', 'Bed', 'Faucet', 'Tent', - 'Horse', 'Mirror', 'Power outlet', 'Sink', 'Apple', 'Air Conditioner', - 'Knife', 'Hockey Stick', 'Paddle', 'Pickup Truck', 'Fork', - 'Traffic Sign', 'Ballon', 'Tripod', 'Dog', 'Spoon', 'Clock', - 'Pot', 'Cow', 'Cake', 'Dinning Table', 'Sheep', 'Hanger', - 'Blackboard/Whiteboard', 'Napkin', 'Other Fish', 'Orange/Tangerine', - 'Toiletry', 'Keyboard', 'Tomato', 'Lantern', 'Machinery Vehicle', - 'Fan', 'Green Vegetables', 'Banana', 'Baseball Glove', 'Airplane', - 'Mouse', 'Train', 'Pumpkin', 'Soccer', 'Skiboard', 'Luggage', - 'Nightstand', 'Tea pot', 'Telephone', 'Trolley', 'Head Phone', - 'Sports Car', 'Stop Sign', 'Dessert', 'Scooter', 'Stroller', 'Crane', - 'Remote', 'Refrigerator', 'Oven', 'Lemon', 'Duck', 'Baseball Bat', - 'Surveillance Camera', 'Cat', 'Jug', 'Broccoli', 'Piano', 'Pizza', - 'Elephant', 'Skateboard', 'Surfboard', 'Gun', 'Skating and Skiing shoes', - 'Gas stove', 'Donut', 'Bow Tie', 'Carrot', 'Toilet', 'Kite', - 'Strawberry', 'Other Balls', 'Shovel', 'Pepper', 'Computer Box', - 'Toilet Paper', 'Cleaning Products', 'Chopsticks', 'Microwave', - 'Pigeon', 'Baseball', 'Cutting/chopping Board', 'Coffee Table', - 'Side Table', 'Scissors', 'Marker', 'Pie', 'Ladder', 'Snowboard', - 'Cookies', 'Radiator', 'Fire Hydrant', 'Basketball', 'Zebra', - 'Grape', 'Giraffe', 'Potato', 'Sausage', 'Tricycle', 'Violin', - 'Egg', 'Fire Extinguisher', 'Candy', 'Fire Truck', 'Billards', - 'Converter', 'Bathtub', 'Wheelchair', 'Golf Club', 'Briefcase', - 'Cucumber', 'Cigar/Cigarette ', 'Paint Brush', 'Pear', 'Heavy Truck', - 'Hamburger', 'Extractor', 'Extention Cord', 'Tong', 'Tennis Racket', - 'Folder', 'American Football', 'earphone', 'Mask', 'Kettle', - 'Tennis', 'Ship', 'Swing', 'Coffee Machine', 'Slide', 'Carriage', - 'Onion', 'Green beans', 'Projector', 'Frisbee', - 'Washing Machine/Drying Machine', 'Chicken', 'Printer', 'Watermelon', - 'Saxophone', 'Tissue', 'Toothbrush', 'Ice cream', 'Hotair ballon', - 'Cello', 'French Fries', 'Scale', 'Trophy', 'Cabbage', 'Hot dog', - 'Blender', 'Peach', 'Rice', 'Wallet/Purse', 'Volleyball', 'Deer', - 'Goose', 'Tape', 'Tablet', 'Cosmetics', 'Trumpet', 'Pineapple', - 'Golf Ball', 'Ambulance', 'Parking meter', 'Mango', 'Key', - 'Hurdle', 'Fishing Rod', 'Medal', 'Flute', 'Brush', 'Penguin', - 'Megaphone', 'Corn', 'Lettuce', 'Garlic', 'Swan', 'Helicopter', - 'Green Onion', 'Sandwich', 'Nuts', 'Speed Limit Sign', - 'Induction Cooker', 'Broom', 'Trombone', 'Plum', 'Rickshaw', - 'Goldfish', 'Kiwi fruit', 'Router/modem', 'Poker Card', 'Toaster', - 'Shrimp', 'Sushi', 'Cheese', 'Notepaper', 'Cherry', 'Pliers', 'CD', - 'Pasta', 'Hammer', 'Cue', 'Avocado', 'Hamimelon', 'Flask', 'Mushroon', - 'Screwdriver', 'Soap', 'Recorder', 'Bear', 'Eggplant', 'Board Eraser', - 'Coconut', 'Tape Measur/ Ruler', 'Pig', 'Showerhead', 'Globe', - 'Chips', 'Steak', 'Crosswalk Sign', 'Stapler', 'Campel', 'Formula 1 ', - 'Pomegranate', 'Dishwasher', 'Crab', 'Hoverboard', 'Meat ball', - 'Rice Cooker', 'Tuba', 'Calculator', 'Papaya', 'Antelope', 'Parrot', - 'Seal', 'Buttefly', 'Dumbbell', 'Donkey', 'Lion', 'Urinal', 'Dolphin', - 'Electric Drill', 'Hair Dryer', 'Egg tart', 'Jellyfish', 'Treadmill', - 'Lighter', 'Grapefruit', 'Game board', 'Mop', 'Radish', 'Baozi', - 'Target', 'French', 'Spring Rolls', 'Monkey', 'Rabbit', 'Pencil Case', - 'Yak', 'Red Cabbage', 'Binoculars', 'Asparagus', 'Barbell', 'Scallop', - 'Noddles', 'Comb', 'Dumpling', 'Oyster', 'Table Teniis paddle', - 'Cosmetics Brush/Eyeliner Pencil', 'Chainsaw', 'Eraser', 'Lobster', - 'Durian', 'Okra', 'Lipstick', 'Cosmetics Mirror', 'Curling', - 'Table Tennis'] - diff --git a/data/objects365.yaml b/data/objects365.yaml new file mode 100644 index 000000000000..a85469d6868f --- /dev/null +++ b/data/objects365.yaml @@ -0,0 +1,57 @@ +# Objects365 dataset https://www.objects365.org/ +# Train command: python train.py --data objects365.yaml +# Default dataset location is next to YOLOv5: +# /parent_folder +# /datasets/objects365 +# /yolov5 + +# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] +train: ../datasets/objects365/images/train # 1.7 Million images +val: ../datasets/objects365/images/val # 5570 images + +# number of classes +nc: 365 + +# class names +names: [ 'Person', 'Sneakers', 'Chair', 'Other Shoes', 'Hat', 'Car', 'Lamp', 'Glasses', 'Bottle', 'Desk', 'Cup', + 'Street Lights', 'Cabinet/shelf', 'Handbag/Satchel', 'Bracelet', 'Plate', 'Picture/Frame', 'Helmet', 'Book', + 'Gloves', 'Storage box', 'Boat', 'Leather Shoes', 'Flower', 'Bench', 'Potted Plant', 'Bowl/Basin', 'Flag', + 'Pillow', 'Boots', 'Vase', 'Microphone', 'Necklace', 'Ring', 'SUV', 'Wine Glass', 'Belt', 'Moniter/TV', + 'Backpack', 'Umbrella', 'Traffic Light', 'Speaker', 'Watch', 'Tie', 'Trash bin Can', 'Slippers', 'Bicycle', + 'Stool', 'Barrel/bucket', 'Van', 'Couch', 'Sandals', 'Bakset', 'Drum', 'Pen/Pencil', 'Bus', 'Wild Bird', + 'High Heels', 'Motorcycle', 'Guitar', 'Carpet', 'Cell Phone', 'Bread', 'Camera', 'Canned', 'Truck', + 'Traffic cone', 'Cymbal', 'Lifesaver', 'Towel', 'Stuffed Toy', 'Candle', 'Sailboat', 'Laptop', 'Awning', + 'Bed', 'Faucet', 'Tent', 'Horse', 'Mirror', 'Power outlet', 'Sink', 'Apple', 'Air Conditioner', 'Knife', + 'Hockey Stick', 'Paddle', 'Pickup Truck', 'Fork', 'Traffic Sign', 'Ballon', 'Tripod', 'Dog', 'Spoon', 'Clock', + 'Pot', 'Cow', 'Cake', 'Dinning Table', 'Sheep', 'Hanger', 'Blackboard/Whiteboard', 'Napkin', 'Other Fish', + 'Orange/Tangerine', 'Toiletry', 'Keyboard', 'Tomato', 'Lantern', 'Machinery Vehicle', 'Fan', + 'Green Vegetables', 'Banana', 'Baseball Glove', 'Airplane', 'Mouse', 'Train', 'Pumpkin', 'Soccer', 'Skiboard', + 'Luggage', 'Nightstand', 'Tea pot', 'Telephone', 'Trolley', 'Head Phone', 'Sports Car', 'Stop Sign', + 'Dessert', 'Scooter', 'Stroller', 'Crane', 'Remote', 'Refrigerator', 'Oven', 'Lemon', 'Duck', 'Baseball Bat', + 'Surveillance Camera', 'Cat', 'Jug', 'Broccoli', 'Piano', 'Pizza', 'Elephant', 'Skateboard', 'Surfboard', + 'Gun', 'Skating and Skiing shoes', 'Gas stove', 'Donut', 'Bow Tie', 'Carrot', 'Toilet', 'Kite', 'Strawberry', + 'Other Balls', 'Shovel', 'Pepper', 'Computer Box', 'Toilet Paper', 'Cleaning Products', 'Chopsticks', + 'Microwave', 'Pigeon', 'Baseball', 'Cutting/chopping Board', 'Coffee Table', 'Side Table', 'Scissors', + 'Marker', 'Pie', 'Ladder', 'Snowboard', 'Cookies', 'Radiator', 'Fire Hydrant', 'Basketball', 'Zebra', 'Grape', + 'Giraffe', 'Potato', 'Sausage', 'Tricycle', 'Violin', 'Egg', 'Fire Extinguisher', 'Candy', 'Fire Truck', + 'Billards', 'Converter', 'Bathtub', 'Wheelchair', 'Golf Club', 'Briefcase', 'Cucumber', 'Cigar/Cigarette', + 'Paint Brush', 'Pear', 'Heavy Truck', 'Hamburger', 'Extractor', 'Extention Cord', 'Tong', 'Tennis Racket', + 'Folder', 'American Football', 'earphone', 'Mask', 'Kettle', 'Tennis', 'Ship', 'Swing', 'Coffee Machine', + 'Slide', 'Carriage', 'Onion', 'Green beans', 'Projector', 'Frisbee', 'Washing Machine/Drying Machine', + 'Chicken', 'Printer', 'Watermelon', 'Saxophone', 'Tissue', 'Toothbrush', 'Ice cream', 'Hotair ballon', + 'Cello', 'French Fries', 'Scale', 'Trophy', 'Cabbage', 'Hot dog', 'Blender', 'Peach', 'Rice', 'Wallet/Purse', + 'Volleyball', 'Deer', 'Goose', 'Tape', 'Tablet', 'Cosmetics', 'Trumpet', 'Pineapple', 'Golf Ball', + 'Ambulance', 'Parking meter', 'Mango', 'Key', 'Hurdle', 'Fishing Rod', 'Medal', 'Flute', 'Brush', 'Penguin', + 'Megaphone', 'Corn', 'Lettuce', 'Garlic', 'Swan', 'Helicopter', 'Green Onion', 'Sandwich', 'Nuts', + 'Speed Limit Sign', 'Induction Cooker', 'Broom', 'Trombone', 'Plum', 'Rickshaw', 'Goldfish', 'Kiwi fruit', + 'Router/modem', 'Poker Card', 'Toaster', 'Shrimp', 'Sushi', 'Cheese', 'Notepaper', 'Cherry', 'Pliers', 'CD', + 'Pasta', 'Hammer', 'Cue', 'Avocado', 'Hamimelon', 'Flask', 'Mushroon', 'Screwdriver', 'Soap', 'Recorder', + 'Bear', 'Eggplant', 'Board Eraser', 'Coconut', 'Tape Measur/ Ruler', 'Pig', 'Showerhead', 'Globe', 'Chips', + 'Steak', 'Crosswalk Sign', 'Stapler', 'Campel', 'Formula 1', 'Pomegranate', 'Dishwasher', 'Crab', + 'Hoverboard', 'Meat ball', 'Rice Cooker', 'Tuba', 'Calculator', 'Papaya', 'Antelope', 'Parrot', 'Seal', + 'Buttefly', 'Dumbbell', 'Donkey', 'Lion', 'Urinal', 'Dolphin', 'Electric Drill', 'Hair Dryer', 'Egg tart', + 'Jellyfish', 'Treadmill', 'Lighter', 'Grapefruit', 'Game board', 'Mop', 'Radish', 'Baozi', 'Target', 'French', + 'Spring Rolls', 'Monkey', 'Rabbit', 'Pencil Case', 'Yak', 'Red Cabbage', 'Binoculars', 'Asparagus', 'Barbell', + 'Scallop', 'Noddles', 'Comb', 'Dumpling', 'Oyster', 'Table Teniis paddle', 'Cosmetics Brush/Eyeliner Pencil', + 'Chainsaw', 'Eraser', 'Lobster', 'Durian', 'Okra', 'Lipstick', 'Cosmetics Mirror', 'Curling', 'Table Tennis' ] + diff --git a/data/scripts/get_objects365.py b/data/scripts/get_objects365.py new file mode 100644 index 000000000000..fcb07d246fea --- /dev/null +++ b/data/scripts/get_objects365.py @@ -0,0 +1,38 @@ +import cv2 +from pycocotools.coco import COCO + +# Create the following folder structure: +# datasets/object365/images/train, datasets/object365/images/val, datasets/labels/train, dataset/labels/val + +# Download Object 365 from the Object 365 website And unpack all images in datasets/object365/images/train, +# Put The script and zhiyuan_objv2_train.json file in dataset/object365 +# Execute the script in datasets/object365 path + +coco = COCO("zhiyuan_objv2_train.json") +cats = coco.loadCats(coco.getCatIds()) +nms = [cat["name"] for cat in cats] +print("COCO categories: \n{}\n".format(" ".join(nms))) +cash = set() +for categoryId, cat in enumerate(nms): + catIds = coco.getCatIds(catNms=[cat]) + imgIds = coco.getImgIds(catIds=catIds) + print(cat) + # Create a subfolder in this directory called "labels". This is where the annotations will be saved in YOLO format + for im in coco.loadImgs(imgIds): + width, height = im["width"], im["height"] + path = im["file_name"].split("/")[-1] # image filename + try: + # Test image for missing images + if path not in cash: + img = cv2.cvtColor(cv2.imread(f"images/train/{path}"), cv2.COLOR_BGR2RGB) + cash.add(path) + + with open("labels/train/" + path.replace(".jpg", ".txt"), "a+") as file: + annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None) + for a in coco.loadAnns(annIds): + x, y, w, h = a['bbox'] # bounding box in xywh (xy top-left corner) + x, y = x + w / 2, y + h / 2 # xy to center + file.write(f"{categoryId} {x / width:.5f} {y / height:.5f} {w / width:.5f} {h / height:.5f}\n") + + except Exception as e: + print(e) diff --git a/data/scripts/object365-to-yolo-format.py b/data/scripts/object365-to-yolo-format.py deleted file mode 100644 index e5ac7c9f8578..000000000000 --- a/data/scripts/object365-to-yolo-format.py +++ /dev/null @@ -1,84 +0,0 @@ -from pycocotools.coco import COCO -import cv2 -import numpy as np -import glob -import shutil - -# Truncates numbers to N decimals -def truncate(n, decimals=0): - multiplier = 10 ** decimals - return int(n * multiplier) / multiplier - - -# Create the following folder structure dataset/object365/images/train, dataset/object365/images/val, dataset/labels/images/train, dataset/labels/images/val - -# Download Object 365 from the Object 365 website And unpack all images in dataset/object365/images/train,Put The script and zhiyuan_objv2_train.json file in dataset/object365 -# Execute the script in dataset/object365v path - - -coco = COCO("zhiyuan_objv2_train.json") -cats = coco.loadCats(coco.getCatIds()) -nms = [cat["name"] for cat in cats] -print("COCO categories: \n{}\n".format(" ".join(nms))) -cash = set() - -for categoryId, cat in enumerate(nms): - catIds = coco.getCatIds(catNms=[cat]) - imgIds = coco.getImgIds(catIds=catIds) - images = coco.loadImgs(imgIds) - print(cat) - # # Create a subfolder in this directory called "labels". This is where the annotations will be saved in YOLO format - for im in images: - dw = 1.0 / im["width"] - dh = 1.0 / im["height"] - - annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None) - anns = coco.loadAnns(annIds) - - path = im["file_name"].split("/") - fixed_path = path[-1] - filename = fixed_path.replace(".jpg", ".txt") - - try: - # Test image for missing images - if fixed_path not in cash: - img = cv2.imread(f"images/train/{fixed_path}") - img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) - cash.add(fixed_path) - - with open("labels/train/" + filename, "a+") as myfile: - for i in range(len(anns)): - xmin = anns[i]["bbox"][0] - ymin = anns[i]["bbox"][1] - xmax = anns[i]["bbox"][2] + anns[i]["bbox"][0] - ymax = anns[i]["bbox"][3] + anns[i]["bbox"][1] - - x = (xmin + xmax) / 2 - y = (ymin + ymax) / 2 - - w = xmax - xmin - h = ymax - ymin - - x = x * dw - w = w * dw - y = y * dh - h = h * dh - - # Note: This assumes a single-category dataset, and thus the "0" at the beginning of each line. - mystring = f"{categoryId} {truncate(x, 7)} {truncate(y, 7)} {truncate(w, 7)} {truncate(h, 7)}" - myfile.write(mystring) - myfile.write("\n") - myfile.close() - - except Exception as e: - print(e) - -current_dir = "images/train" -chances = 10 # 10% val set -for fullpath in glob.iglob(os.path.join(current_dir, "*.jpg")): - n = random.randint(1, 100) - if n <= chances: - title, ext = os.path.splitext(os.path.basename(fullpath)) - print(title) - shutil.move(f"images/train/{title}.jpg", f"images/val/{title}.jpg") - shutil.move(f"labels/train/{title}.txt", f"labels/val/{title}.txt") From 3220e04a191cf4b937a00398fabd1086dc60860f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 29 Apr 2021 00:05:28 +0200 Subject: [PATCH 5/6] spelling --- data/objects365.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/data/objects365.yaml b/data/objects365.yaml index a85469d6868f..14464694f53a 100644 --- a/data/objects365.yaml +++ b/data/objects365.yaml @@ -16,13 +16,13 @@ nc: 365 names: [ 'Person', 'Sneakers', 'Chair', 'Other Shoes', 'Hat', 'Car', 'Lamp', 'Glasses', 'Bottle', 'Desk', 'Cup', 'Street Lights', 'Cabinet/shelf', 'Handbag/Satchel', 'Bracelet', 'Plate', 'Picture/Frame', 'Helmet', 'Book', 'Gloves', 'Storage box', 'Boat', 'Leather Shoes', 'Flower', 'Bench', 'Potted Plant', 'Bowl/Basin', 'Flag', - 'Pillow', 'Boots', 'Vase', 'Microphone', 'Necklace', 'Ring', 'SUV', 'Wine Glass', 'Belt', 'Moniter/TV', + 'Pillow', 'Boots', 'Vase', 'Microphone', 'Necklace', 'Ring', 'SUV', 'Wine Glass', 'Belt', 'Monitor/TV', 'Backpack', 'Umbrella', 'Traffic Light', 'Speaker', 'Watch', 'Tie', 'Trash bin Can', 'Slippers', 'Bicycle', - 'Stool', 'Barrel/bucket', 'Van', 'Couch', 'Sandals', 'Bakset', 'Drum', 'Pen/Pencil', 'Bus', 'Wild Bird', + 'Stool', 'Barrel/bucket', 'Van', 'Couch', 'Sandals', 'Basket', 'Drum', 'Pen/Pencil', 'Bus', 'Wild Bird', 'High Heels', 'Motorcycle', 'Guitar', 'Carpet', 'Cell Phone', 'Bread', 'Camera', 'Canned', 'Truck', 'Traffic cone', 'Cymbal', 'Lifesaver', 'Towel', 'Stuffed Toy', 'Candle', 'Sailboat', 'Laptop', 'Awning', 'Bed', 'Faucet', 'Tent', 'Horse', 'Mirror', 'Power outlet', 'Sink', 'Apple', 'Air Conditioner', 'Knife', - 'Hockey Stick', 'Paddle', 'Pickup Truck', 'Fork', 'Traffic Sign', 'Ballon', 'Tripod', 'Dog', 'Spoon', 'Clock', + 'Hockey Stick', 'Paddle', 'Pickup Truck', 'Fork', 'Traffic Sign', 'Balloon', 'Tripod', 'Dog', 'Spoon', 'Clock', 'Pot', 'Cow', 'Cake', 'Dinning Table', 'Sheep', 'Hanger', 'Blackboard/Whiteboard', 'Napkin', 'Other Fish', 'Orange/Tangerine', 'Toiletry', 'Keyboard', 'Tomato', 'Lantern', 'Machinery Vehicle', 'Fan', 'Green Vegetables', 'Banana', 'Baseball Glove', 'Airplane', 'Mouse', 'Train', 'Pumpkin', 'Soccer', 'Skiboard', @@ -34,24 +34,24 @@ names: [ 'Person', 'Sneakers', 'Chair', 'Other Shoes', 'Hat', 'Car', 'Lamp', 'Gl 'Microwave', 'Pigeon', 'Baseball', 'Cutting/chopping Board', 'Coffee Table', 'Side Table', 'Scissors', 'Marker', 'Pie', 'Ladder', 'Snowboard', 'Cookies', 'Radiator', 'Fire Hydrant', 'Basketball', 'Zebra', 'Grape', 'Giraffe', 'Potato', 'Sausage', 'Tricycle', 'Violin', 'Egg', 'Fire Extinguisher', 'Candy', 'Fire Truck', - 'Billards', 'Converter', 'Bathtub', 'Wheelchair', 'Golf Club', 'Briefcase', 'Cucumber', 'Cigar/Cigarette', - 'Paint Brush', 'Pear', 'Heavy Truck', 'Hamburger', 'Extractor', 'Extention Cord', 'Tong', 'Tennis Racket', + 'Billiards', 'Converter', 'Bathtub', 'Wheelchair', 'Golf Club', 'Briefcase', 'Cucumber', 'Cigar/Cigarette', + 'Paint Brush', 'Pear', 'Heavy Truck', 'Hamburger', 'Extractor', 'Extension Cord', 'Tong', 'Tennis Racket', 'Folder', 'American Football', 'earphone', 'Mask', 'Kettle', 'Tennis', 'Ship', 'Swing', 'Coffee Machine', 'Slide', 'Carriage', 'Onion', 'Green beans', 'Projector', 'Frisbee', 'Washing Machine/Drying Machine', - 'Chicken', 'Printer', 'Watermelon', 'Saxophone', 'Tissue', 'Toothbrush', 'Ice cream', 'Hotair ballon', + 'Chicken', 'Printer', 'Watermelon', 'Saxophone', 'Tissue', 'Toothbrush', 'Ice cream', 'Hot-air balloon', 'Cello', 'French Fries', 'Scale', 'Trophy', 'Cabbage', 'Hot dog', 'Blender', 'Peach', 'Rice', 'Wallet/Purse', 'Volleyball', 'Deer', 'Goose', 'Tape', 'Tablet', 'Cosmetics', 'Trumpet', 'Pineapple', 'Golf Ball', 'Ambulance', 'Parking meter', 'Mango', 'Key', 'Hurdle', 'Fishing Rod', 'Medal', 'Flute', 'Brush', 'Penguin', 'Megaphone', 'Corn', 'Lettuce', 'Garlic', 'Swan', 'Helicopter', 'Green Onion', 'Sandwich', 'Nuts', 'Speed Limit Sign', 'Induction Cooker', 'Broom', 'Trombone', 'Plum', 'Rickshaw', 'Goldfish', 'Kiwi fruit', 'Router/modem', 'Poker Card', 'Toaster', 'Shrimp', 'Sushi', 'Cheese', 'Notepaper', 'Cherry', 'Pliers', 'CD', - 'Pasta', 'Hammer', 'Cue', 'Avocado', 'Hamimelon', 'Flask', 'Mushroon', 'Screwdriver', 'Soap', 'Recorder', - 'Bear', 'Eggplant', 'Board Eraser', 'Coconut', 'Tape Measur/ Ruler', 'Pig', 'Showerhead', 'Globe', 'Chips', - 'Steak', 'Crosswalk Sign', 'Stapler', 'Campel', 'Formula 1', 'Pomegranate', 'Dishwasher', 'Crab', + 'Pasta', 'Hammer', 'Cue', 'Avocado', 'Hamimelon', 'Flask', 'Mushroom', 'Screwdriver', 'Soap', 'Recorder', + 'Bear', 'Eggplant', 'Board Eraser', 'Coconut', 'Tape Measure/Ruler', 'Pig', 'Showerhead', 'Globe', 'Chips', + 'Steak', 'Crosswalk Sign', 'Stapler', 'Camel', 'Formula 1', 'Pomegranate', 'Dishwasher', 'Crab', 'Hoverboard', 'Meat ball', 'Rice Cooker', 'Tuba', 'Calculator', 'Papaya', 'Antelope', 'Parrot', 'Seal', - 'Buttefly', 'Dumbbell', 'Donkey', 'Lion', 'Urinal', 'Dolphin', 'Electric Drill', 'Hair Dryer', 'Egg tart', + 'Butterfly', 'Dumbbell', 'Donkey', 'Lion', 'Urinal', 'Dolphin', 'Electric Drill', 'Hair Dryer', 'Egg tart', 'Jellyfish', 'Treadmill', 'Lighter', 'Grapefruit', 'Game board', 'Mop', 'Radish', 'Baozi', 'Target', 'French', 'Spring Rolls', 'Monkey', 'Rabbit', 'Pencil Case', 'Yak', 'Red Cabbage', 'Binoculars', 'Asparagus', 'Barbell', - 'Scallop', 'Noddles', 'Comb', 'Dumpling', 'Oyster', 'Table Teniis paddle', 'Cosmetics Brush/Eyeliner Pencil', + 'Scallop', 'Noddles', 'Comb', 'Dumpling', 'Oyster', 'Table Tennis paddle', 'Cosmetics Brush/Eyeliner Pencil', 'Chainsaw', 'Eraser', 'Lobster', 'Durian', 'Okra', 'Lipstick', 'Cosmetics Mirror', 'Curling', 'Table Tennis' ] From d80eeae42dd0ca97ea69b67d78d82af73e27e7e4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 29 Apr 2021 20:34:54 +0200 Subject: [PATCH 6/6] Update get_objects365.py --- data/scripts/get_objects365.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/data/scripts/get_objects365.py b/data/scripts/get_objects365.py index fcb07d246fea..309e6d3f2b64 100644 --- a/data/scripts/get_objects365.py +++ b/data/scripts/get_objects365.py @@ -1,18 +1,18 @@ -import cv2 -from pycocotools.coco import COCO - -# Create the following folder structure: -# datasets/object365/images/train, datasets/object365/images/val, datasets/labels/train, dataset/labels/val +# Objects365 https://www.objects365.org labels JSON to YOLO script +# 1. Download Object 365 from the Object 365 website And unpack all images in datasets/object365/images +# 2. Place this file and zhiyuan_objv2_train.json file in datasets/objects365 +# 3. Execute this file from datasets/object365 path +# /datasets +# /objects365 +# /images +# /labels -# Download Object 365 from the Object 365 website And unpack all images in datasets/object365/images/train, -# Put The script and zhiyuan_objv2_train.json file in dataset/object365 -# Execute the script in datasets/object365 path +from pycocotools.coco import COCO coco = COCO("zhiyuan_objv2_train.json") cats = coco.loadCats(coco.getCatIds()) nms = [cat["name"] for cat in cats] print("COCO categories: \n{}\n".format(" ".join(nms))) -cash = set() for categoryId, cat in enumerate(nms): catIds = coco.getCatIds(catNms=[cat]) imgIds = coco.getImgIds(catIds=catIds) @@ -22,11 +22,6 @@ width, height = im["width"], im["height"] path = im["file_name"].split("/")[-1] # image filename try: - # Test image for missing images - if path not in cash: - img = cv2.cvtColor(cv2.imread(f"images/train/{path}"), cv2.COLOR_BGR2RGB) - cash.add(path) - with open("labels/train/" + path.replace(".jpg", ".txt"), "a+") as file: annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None) for a in coco.loadAnns(annIds):