From bd11660f825dcd2d65c19f631ea4e8c0aa8c4d53 Mon Sep 17 00:00:00 2001 From: chuneuny <emily.chun@intel.com> Date: Fri, 12 Mar 2021 10:16:45 +0900 Subject: [PATCH 1/7] Add OpenVINO interpreter samples --- .../openvino_interpreter_samples/README.md | 39 + .../openvino_interpreter_samples/coco.class | 91 ++ .../imagenet.class | 1000 +++++++++++++++++ .../mobilenet_v2_pytorch_interp.py | 40 + .../ssd_face_detection_interp.py | 93 ++ .../ssd_mobilenet_coco_detection_interp.py | 102 ++ .../ssd_person_detection_interp.py | 93 ++ ...sd_person_vehicle_bike_detection_interp.py | 95 ++ .../ssd_vehicle_detection_interp.py | 93 ++ 9 files changed, 1646 insertions(+) create mode 100644 datumaro/plugins/openvino_interpreter_samples/README.md create mode 100644 datumaro/plugins/openvino_interpreter_samples/coco.class create mode 100644 datumaro/plugins/openvino_interpreter_samples/imagenet.class create mode 100644 datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py create mode 100644 datumaro/plugins/openvino_interpreter_samples/ssd_face_detection_interp.py create mode 100644 datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py create mode 100644 datumaro/plugins/openvino_interpreter_samples/ssd_person_detection_interp.py create mode 100644 datumaro/plugins/openvino_interpreter_samples/ssd_person_vehicle_bike_detection_interp.py create mode 100644 datumaro/plugins/openvino_interpreter_samples/ssd_vehicle_detection_interp.py diff --git a/datumaro/plugins/openvino_interpreter_samples/README.md b/datumaro/plugins/openvino_interpreter_samples/README.md new file mode 100644 index 0000000000..ca56cb261f --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/README.md @@ -0,0 +1,39 @@ +# OpenVINO Inference Interpreter +Interpreter samples to parse OpenVINO inference outputs. + +## Models supported from interpreter samples + +- Intel Pre-trained Models + - Object Detection + - face-detection-0200 (https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0200_description_face_detection_0200.html) + - face-detection-0202 (https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0202_description_face_detection_0202.html) + - face-detection-0204 (https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0204_description_face_detection_0204.html) + - person-detection-0200 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0200_description_person_detection_0200.html) + - person-detection-0201 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0201_description_person_detection_0201.html) + - person-detection-0202 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0202_description_person_detection_0202.html) + - person-vehicle-bike-detection-2000 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2000_description_person_vehicle_bike_detection_2000.html) + - person-vehicle-bike-detection-2001 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2001_description_person_vehicle_bike_detection_2001.html) + - person-vehicle-bike-detection-2002 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2002_description_person_vehicle_bike_detection_2002.html) + - vehicle-detection-0200 (https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0200_description_vehicle_detection_0200.html) + - vehicle-detection-0201 (https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0201_description_vehicle_detection_0201.html) + - vehicle-detection-0202 (https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0202_description_vehicle_detection_0202.html) + +- Public Pre-Trained Models(OMZ) + - Classification + - mobilenet-v2-pytorch (https://docs.openvinotoolkit.org/latest/omz_models_public_mobilenet_v2_pytorch_mobilenet_v2_pytorch.html) + - Object Detection + - ssd_mobilenet_v1_coco (https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v1_coco_ssd_mobilenet_v1_coco.html) + - ssd_mobilenet_v2_coco (https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v2_coco_ssd_mobilenet_v2_coco.html) + +## Model download +- Prerequisites: OpenVINO (For installation, please see https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html) +- To download OpenVINO models, please see https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html + + ```bash + # cd <openvino_directory>/deployment_tools/open_model_zoo/tools/downloader + # ./downloader.py --name <model_name> + # + # Examples + cd /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader + ./downloader.py --name face-detection-0200 + ``` \ No newline at end of file diff --git a/datumaro/plugins/openvino_interpreter_samples/coco.class b/datumaro/plugins/openvino_interpreter_samples/coco.class new file mode 100644 index 0000000000..9682e2b88c --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/coco.class @@ -0,0 +1,91 @@ +person +bicycle +car +motorcycle +airplane +bus +train +truck +boat +trafficlight +firehydrant +streetsign +stopsign +parkingmeter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +hat +backpack +umbrella +shoe +eyeglasses +handbag +tie +suitcase +frisbee +skis +snowboard +sportsball +kite +baseballbat +baseballglove +skateboard +surfboard +tennisracket +bottle +plate +wineglass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hotdog +pizza +donut +cake +chair +couch +pottedplant +bed +mirror +diningtable +window +desk +toilet +door +tv +laptop +mouse +remote +keyboard +cellphone +microwave +oven +toaster +sink +refrigerator +blender +book +clock +vase +scissors +teddybear +hairdrier +toothbrush +hairbrush \ No newline at end of file diff --git a/datumaro/plugins/openvino_interpreter_samples/imagenet.class b/datumaro/plugins/openvino_interpreter_samples/imagenet.class new file mode 100644 index 0000000000..2571d1b729 --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/imagenet.class @@ -0,0 +1,1000 @@ +tench +goldfish +great white shark +tiger shark +hammerhead +electric ray +stingray +cock +hen +ostrich +brambling +goldfinch +house finch +junco +indigo bunting +robin +bulbul +jay +magpie +chickadee +water ouzel +kite +bald eagle +vulture +great grey owl +European fire salamander +common newt +eft +spotted salamander +axolotl +bullfrog +tree frog +tailed frog +loggerhead +leatherback turtle +mud turtle +terrapin +box turtle +banded gecko +common iguana +American chameleon +whiptail +agama +frilled lizard +alligator lizard +Gila monster +green lizard +African chameleon +Komodo dragon +African crocodile +American alligator +triceratops +thunder snake +ringneck snake +hognose snake +green snake +king snake +garter snake +water snake +vine snake +night snake +boa constrictor +rock python +Indian cobra +green mamba +sea snake +horned viper +diamondback +sidewinder +trilobite +harvestman +scorpion +black and gold garden spider +barn spider +garden spider +black widow +tarantula +wolf spider +tick +centipede +black grouse +ptarmigan +ruffed grouse +prairie chicken +peacock +quail +partridge +African grey +macaw +sulphur-crested cockatoo +lorikeet +coucal +bee eater +hornbill +hummingbird +jacamar +toucan +drake +red-breasted merganser +goose +black swan +tusker +echidna +platypus +wallaby +koala +wombat +jellyfish +sea anemone +brain coral +flatworm +nematode +conch +snail +slug +sea slug +chiton +chambered nautilus +Dungeness crab +rock crab +fiddler crab +king crab +American lobster +spiny lobster +crayfish +hermit crab +isopod +white stork +black stork +spoonbill +flamingo +little blue heron +American egret +bittern +crane +limpkin +European gallinule +American coot +bustard +ruddy turnstone +red-backed sandpiper +redshank +dowitcher +oystercatcher +pelican +king penguin +albatross +grey whale +killer whale +dugong +sea lion +Chihuahua +Japanese spaniel +Maltese dog +Pekinese +Shih-Tzu +Blenheim spaniel +papillon +toy terrier +Rhodesian ridgeback +Afghan hound +basset +beagle +bloodhound +bluetick +black-and-tan coonhound +Walker hound +English foxhound +redbone +borzoi +Irish wolfhound +Italian greyhound +whippet +Ibizan hound +Norwegian elkhound +otterhound +Saluki +Scottish deerhound +Weimaraner +Staffordshire bullterrier +American Staffordshire terrier +Bedlington terrier +Border terrier +Kerry blue terrier +Irish terrier +Norfolk terrier +Norwich terrier +Yorkshire terrier +wire-haired fox terrier +Lakeland terrier +Sealyham terrier +Airedale +cairn +Australian terrier +Dandie Dinmont +Boston bull +miniature schnauzer +giant schnauzer +standard schnauzer +Scotch terrier +Tibetan terrier +silky terrier +soft-coated wheaten terrier +West Highland white terrier +Lhasa +flat-coated retriever +curly-coated retriever +golden retriever +Labrador retriever +Chesapeake Bay retriever +German short-haired pointer +vizsla +English setter +Irish setter +Gordon setter +Brittany spaniel +clumber +English springer +Welsh springer spaniel +cocker spaniel +Sussex spaniel +Irish water spaniel +kuvasz +schipperke +groenendael +malinois +briard +kelpie +komondor +Old English sheepdog +Shetland sheepdog +collie +Border collie +Bouvier des Flandres +Rottweiler +German shepherd +Doberman +miniature pinscher +Greater Swiss Mountain dog +Bernese mountain dog +Appenzeller +EntleBucher +boxer +bull mastiff +Tibetan mastiff +French bulldog +Great Dane +Saint Bernard +Eskimo dog +malamute +Siberian husky +dalmatian +affenpinscher +basenji +pug +Leonberg +Newfoundland +Great Pyrenees +Samoyed +Pomeranian +chow +keeshond +Brabancon griffon +Pembroke +Cardigan +toy poodle +miniature poodle +standard poodle +Mexican hairless +timber wolf +white wolf +red wolf +coyote +dingo +dhole +African hunting dog +hyena +red fox +kit fox +Arctic fox +grey fox +tabby +tiger cat +Persian cat +Siamese cat +Egyptian cat +cougar +lynx +leopard +snow leopard +jaguar +lion +tiger +cheetah +brown bear +American black bear +ice bear +sloth bear +mongoose +meerkat +tiger beetle +ladybug +ground beetle +long-horned beetle +leaf beetle +dung beetle +rhinoceros beetle +weevil +fly +bee +ant +grasshopper +cricket +walking stick +cockroach +mantis +cicada +leafhopper +lacewing +dragonfly +damselfly +admiral +ringlet +monarch +cabbage butterfly +sulphur butterfly +lycaenid +starfish +sea urchin +sea cucumber +wood rabbit +hare +Angora +hamster +porcupine +fox squirrel +marmot +beaver +guinea pig +sorrel +zebra +hog +wild boar +warthog +hippopotamus +ox +water buffalo +bison +ram +bighorn +ibex +hartebeest +impala +gazelle +Arabian camel +llama +weasel +mink +polecat +black-footed ferret +otter +skunk +badger +armadillo +three-toed sloth +orangutan +gorilla +chimpanzee +gibbon +siamang +guenon +patas +baboon +macaque +langur +colobus +proboscis monkey +marmoset +capuchin +howler monkey +titi +spider monkey +squirrel monkey +Madagascar cat +indri +Indian elephant +African elephant +lesser panda +giant panda +barracouta +eel +coho +rock beauty +anemone fish +sturgeon +gar +lionfish +puffer +abacus +abaya +academic gown +accordion +acoustic guitar +aircraft carrier +airliner +airship +altar +ambulance +amphibian +analog clock +apiary +apron +ashcan +assault rifle +backpack +bakery +balance beam +balloon +ballpoint +Band Aid +banjo +bannister +barbell +barber chair +barbershop +barn +barometer +barrel +barrow +baseball +basketball +bassinet +bassoon +bathing cap +bath towel +bathtub +beach wagon +beacon +beaker +bearskin +beer bottle +beer glass +bell cote +bib +bicycle-built-for-two +bikini +binder +binoculars +birdhouse +boathouse +bobsled +bolo tie +bonnet +bookcase +bookshop +bottlecap +bow +bow tie +brass +brassiere +breakwater +breastplate +broom +bucket +buckle +bulletproof vest +bullet train +butcher shop +cab +caldron +candle +cannon +canoe +can opener +cardigan +car mirror +carousel +carpenter's kit +carton +car wheel +cash machine +cassette +cassette player +castle +catamaran +CD player +cello +cellular telephone +chain +chainlink fence +chain mail +chain saw +chest +chiffonier +chime +china cabinet +Christmas stocking +church +cinema +cleaver +cliff dwelling +cloak +clog +cocktail shaker +coffee mug +coffeepot +coil +combination lock +computer keyboard +confectionery +container ship +convertible +corkscrew +cornet +cowboy boot +cowboy hat +cradle +crane2 +crash helmet +crate +crib +Crock Pot +croquet ball +crutch +cuirass +dam +desk +desktop computer +dial telephone +diaper +digital clock +digital watch +dining table +dishrag +dishwasher +disk brake +dock +dogsled +dome +doormat +drilling platform +drum +drumstick +dumbbell +Dutch oven +electric fan +electric guitar +electric locomotive +entertainment center +envelope +espresso maker +face powder +feather boa +file +fireboat +fire engine +fire screen +flagpole +flute +folding chair +football helmet +forklift +fountain +fountain pen +four-poster +freight car +French horn +frying pan +fur coat +garbage truck +gasmask +gas pump +goblet +go-kart +golf ball +golfcart +gondola +gong +gown +grand piano +greenhouse +grille +grocery store +guillotine +hair slide +hair spray +half track +hammer +hamper +hand blower +hand-held computer +handkerchief +hard disc +harmonica +harp +harvester +hatchet +holster +home theater +honeycomb +hook +hoopskirt +horizontal bar +horse cart +hourglass +iPod +iron +jack-o'-lantern +jean +jeep +jersey +jigsaw puzzle +jinrikisha +joystick +kimono +knee pad +knot +lab coat +ladle +lampshade +laptop +lawn mower +lens cap +letter opener +library +lifeboat +lighter +limousine +liner +lipstick +Loafer +lotion +loudspeaker +loupe +lumbermill +magnetic compass +mailbag +mailbox +maillot +maillot2 +manhole cover +maraca +marimba +mask +matchstick +maypole +maze +measuring cup +medicine chest +megalith +microphone +microwave +military uniform +milk can +minibus +miniskirt +minivan +missile +mitten +mixing bowl +mobile home +Model T +modem +monastery +monitor +moped +mortar +mortarboard +mosque +mosquito net +motor scooter +mountain bike +mountain tent +mouse +mousetrap +moving van +muzzle +nail +neck brace +necklace +nipple +notebook +obelisk +oboe +ocarina +odometer +oil filter +organ +oscilloscope +overskirt +oxcart +oxygen mask +packet +paddle +paddlewheel +padlock +paintbrush +pajama +palace +panpipe +paper towel +parachute +parallel bars +park bench +parking meter +passenger car +patio +pay-phone +pedestal +pencil box +pencil sharpener +perfume +Petri dish +photocopier +pick +pickelhaube +picket fence +pickup +pier +piggy bank +pill bottle +pillow +ping-pong ball +pinwheel +pirate +pitcher +plane +planetarium +plastic bag +plate rack +plow +plunger +Polaroid camera +pole +police van +poncho +pool table +pop bottle +pot +potter's wheel +power drill +prayer rug +printer +prison +projectile +projector +puck +punching bag +purse +quill +quilt +racer +racket +radiator +radio +radio telescope +rain barrel +recreational vehicle +reel +reflex camera +refrigerator +remote control +restaurant +revolver +rifle +rocking chair +rotisserie +rubber eraser +rugby ball +rule +running shoe +safe +safety pin +saltshaker +sandal +sarong +sax +scabbard +scale +school bus +schooner +scoreboard +screen +screw +screwdriver +seat belt +sewing machine +shield +shoe shop +shoji +shopping basket +shopping cart +shovel +shower cap +shower curtain +ski +ski mask +sleeping bag +slide rule +sliding door +slot +snorkel +snowmobile +snowplow +soap dispenser +soccer ball +sock +solar dish +sombrero +soup bowl +space bar +space heater +space shuttle +spatula +speedboat +spider web +spindle +sports car +spotlight +stage +steam locomotive +steel arch bridge +steel drum +stethoscope +stole +stone wall +stopwatch +stove +strainer +streetcar +stretcher +studio couch +stupa +submarine +suit +sundial +sunglass +sunglasses +sunscreen +suspension bridge +swab +sweatshirt +swimming trunks +swing +switch +syringe +table lamp +tank +tape player +teapot +teddy +television +tennis ball +thatch +theater curtain +thimble +thresher +throne +tile roof +toaster +tobacco shop +toilet seat +torch +totem pole +tow truck +toyshop +tractor +trailer truck +tray +trench coat +tricycle +trimaran +tripod +triumphal arch +trolleybus +trombone +tub +turnstile +typewriter keyboard +umbrella +unicycle +upright +vacuum +vase +vault +velvet +vending machine +vestment +viaduct +violin +volleyball +waffle iron +wall clock +wallet +wardrobe +warplane +washbasin +washer +water bottle +water jug +water tower +whiskey jug +whistle +wig +window screen +window shade +Windsor tie +wine bottle +wing +wok +wooden spoon +wool +worm fence +wreck +yawl +yurt +web site +comic book +crossword puzzle +street sign +traffic light +book jacket +menu +plate +guacamole +consomme +hot pot +trifle +ice cream +ice lolly +French loaf +bagel +pretzel +cheeseburger +hotdog +mashed potato +head cabbage +broccoli +cauliflower +zucchini +spaghetti squash +acorn squash +butternut squash +cucumber +artichoke +bell pepper +cardoon +mushroom +Granny Smith +strawberry +orange +lemon +fig +pineapple +banana +jackfruit +custard apple +pomegranate +hay +carbonara +chocolate sauce +dough +meat loaf +pizza +potpie +burrito +red wine +espresso +cup +eggnog +alp +bubble +cliff +coral reef +geyser +lakeside +promontory +sandbar +seashore +valley +volcano +ballplayer +groom +scuba diver +rapeseed +daisy +yellow lady's slipper +corn +acorn +hip +buckeye +coral fungus +agaric +gyromitra +stinkhorn +earthstar +hen-of-the-woods +bolete +ear +toilet tissue \ No newline at end of file diff --git a/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py b/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py new file mode 100644 index 0000000000..9f7ccb6803 --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py @@ -0,0 +1,40 @@ +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT + + +from datumaro.components.extractor import Label, LabelCategories, AnnotationType +from datumaro.util.annotation_util import softmax + + +def process_outputs(inputs, outputs): + # inputs = model input; array or images; shape = (B, H, W, C) + # outputs = model output; shape = (1, 1, N, 7); N is the number of detected bounding boxes. + # det = [image_id, label(class id), conf, x_min, y_min, x_max, y_max] + # results = conversion result; [[ Annotation, ... ], ... ] + + results = [] + for input, output in zip(inputs, outputs): + image_results = [] + output = softmax(output).tolist() + label = output.index(max(output)) + image_results.append(Label(label=label, attributes={"confidences": output})) + + results.append(image_results[:]) + + return results + + +def get_categories(): + # output categories - label map etc. + + label_categories = LabelCategories() + + with open( + "datumaro/plugins/openvino/interpreters/imagenet.class", "r" + ) as file: + for line in file.readlines(): + label = line.strip() + label_categories.add(label) + + return {AnnotationType.label: label_categories} diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_face_detection_interp.py b/datumaro/plugins/openvino_interpreter_samples/ssd_face_detection_interp.py new file mode 100644 index 0000000000..382aa64441 --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/ssd_face_detection_interp.py @@ -0,0 +1,93 @@ +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT + + +from datumaro.components.extractor import * + +conf_thresh = 0.02 + + +def _match_confs(confs, detections): + matches = [-1] * len(detections) + + queries = {} + for i, det in enumerate(detections): + queries.setdefault(int(det[1]), []).append((det[2], i)) + + found_count = 0 + for i, v in enumerate(confs): + if found_count == len(detections): + break + + for cls_id, query in queries.items(): + if found_count == len(detections): + break + + for q_id, (conf, det_idx) in enumerate(query): + if v[cls_id] == conf: + matches[det_idx] = i + query.pop(q_id) + found_count += 1 + break + + return matches + + +def process_outputs(inputs, outputs): + # inputs = model input; array or images; shape = (B, H, W, C) + # outputs = model output; shape = (1, 1, N, 7); N is the number of detected bounding boxes. + # det = [image_id, label(class id), conf, x_min, y_min, x_max, y_max] + # results = conversion result; [[ Annotation, ... ], ... ] + + results = [] + for input, detections in zip(inputs, outputs["detection_out"]): + + input_height, input_width = input.shape[:2] + + confs = outputs["Softmax_189/Softmax_"] + detections = detections[0] + + conf_ids = _match_confs(confs, detections) + + image_results = [] + for i, det in enumerate(detections): + image_id = int(det[0]) + label = int(det[1]) + conf = float(det[2]) + det_confs = confs[conf_ids[i]] + + if conf <= conf_thresh: + continue + + x = max(int(det[3] * input_width), 0) + y = max(int(det[4] * input_height), 0) + w = min(int(det[5] * input_width - x), input_width) + h = min(int(det[6] * input_height - y), input_height) + + image_results.append( + Bbox( + x, + y, + w, + h, + label=label, + attributes={ + "confidence": conf, + "confidences": list(map(float, det_confs)), + }, + ) + ) + + results.append(image_results) + + return results + + +def get_categories(): + # output categories - label map etc. + + label_categories = LabelCategories() + label_categories.add("face") + + return {AnnotationType.label: label_categories} diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py b/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py new file mode 100644 index 0000000000..d0f3e51548 --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py @@ -0,0 +1,102 @@ +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT + + +from datumaro.components.extractor import * + +conf_thresh = 0.3 +model_class_num = 91 + + +def _match_confs(confs, detections): + matches = [-1] * len(detections) + + queries = {} + for i, det in enumerate(detections): + queries.setdefault(int(det[1]), []).append((det[2], i)) + + found_count = 0 + for i, v in enumerate(confs): + if found_count == len(detections): + break + + for cls_id, query in queries.items(): + if found_count == len(detections): + break + + for q_id, (conf, det_idx) in enumerate(query): + if v[cls_id] == conf: + matches[det_idx] = i + query.pop(q_id) + found_count += 1 + break + + return matches + + +def process_outputs(inputs, outputs): + # inputs = model input; array or images; shape = (B, H, W, C) + # outputs = model output; shape = (1, 1, N, 7); N is the number of detected bounding boxes. + # det = [image_id, label(class id), conf, x_min, y_min, x_max, y_max] + # results = conversion result; [[ Annotation, ... ], ... ] + + results = [] + for input, confs, detections in zip( + inputs, outputs["do_ExpandDims_conf/sigmoid"], outputs["DetectionOutput"] + ): + + input_height, input_width = input.shape[:2] + + confs = confs[0].reshape(-1, model_class_num) + detections = detections[0] + + conf_ids = _match_confs(confs, detections) + + image_results = [] + for i, det in enumerate(detections): + image_id = int(det[0]) + label = int(det[1]) + conf = float(det[2]) + det_confs = confs[conf_ids[i]] + + if conf <= conf_thresh: + continue + + x = max(int(det[3] * input_width), 0) + y = max(int(det[4] * input_height), 0) + w = min(int(det[5] * input_width - x), input_width) + h = min(int(det[6] * input_height - y), input_height) + + image_results.append( + Bbox( + x, + y, + w, + h, + label=label, + attributes={ + "confidence": conf, + "confidences": list(map(float, det_confs)), + }, + ) + ) + + results.append(image_results) + + return results + + +def get_categories(): + # output categories - label map etc. + + label_categories = LabelCategories() + + with open( + "datumaro/plugins/openvino/interpreters/coco.class", "r" + ) as file: + for line in file.readlines(): + label = line.strip() + label_categories.add(label) + + return {AnnotationType.label: label_categories} diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_person_detection_interp.py b/datumaro/plugins/openvino_interpreter_samples/ssd_person_detection_interp.py new file mode 100644 index 0000000000..9b4e00d8c4 --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/ssd_person_detection_interp.py @@ -0,0 +1,93 @@ +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT + + +from datumaro.components.extractor import * + +conf_thresh = 0.02 + + +def _match_confs(confs, detections): + matches = [-1] * len(detections) + + queries = {} + for i, det in enumerate(detections): + queries.setdefault(int(det[1]), []).append((det[2], i)) + + found_count = 0 + for i, v in enumerate(confs): + if found_count == len(detections): + break + + for cls_id, query in queries.items(): + if found_count == len(detections): + break + + for q_id, (conf, det_idx) in enumerate(query): + if v[cls_id] == conf: + matches[det_idx] = i + query.pop(q_id) + found_count += 1 + break + + return matches + + +def process_outputs(inputs, outputs): + # inputs = model input; array or images; shape = (B, H, W, C) + # outputs = model output; shape = (1, 1, N, 7); N is the number of detected bounding boxes. + # det = [image_id, label(class id), conf, x_min, y_min, x_max, y_max] + # results = conversion result; [[ Annotation, ... ], ... ] + + results = [] + for input, detections in zip(inputs, outputs["detection_out"]): + + input_height, input_width = input.shape[:2] + + confs = outputs["Softmax_189/Softmax_"] + detections = detections[0] + + conf_ids = _match_confs(confs, detections) + + image_results = [] + for i, det in enumerate(detections): + image_id = int(det[0]) + label = int(det[1]) + conf = float(det[2]) + det_confs = confs[conf_ids[i]] + + if conf <= conf_thresh: + continue + + x = max(int(det[3] * input_width), 0) + y = max(int(det[4] * input_height), 0) + w = min(int(det[5] * input_width - x), input_width) + h = min(int(det[6] * input_height - y), input_height) + + image_results.append( + Bbox( + x, + y, + w, + h, + label=label, + attributes={ + "confidence": conf, + "confidences": list(map(float, det_confs)), + }, + ) + ) + + results.append(image_results) + + return results + + +def get_categories(): + # output categories - label map etc. + + label_categories = LabelCategories() + label_categories.add("person") + + return {AnnotationType.label: label_categories} diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_person_vehicle_bike_detection_interp.py b/datumaro/plugins/openvino_interpreter_samples/ssd_person_vehicle_bike_detection_interp.py new file mode 100644 index 0000000000..763180386d --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/ssd_person_vehicle_bike_detection_interp.py @@ -0,0 +1,95 @@ +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT + + +from datumaro.components.extractor import * + +conf_thresh = 0.02 + + +def _match_confs(confs, detections): + matches = [-1] * len(detections) + + queries = {} + for i, det in enumerate(detections): + queries.setdefault(int(det[1]), []).append((det[2], i)) + + found_count = 0 + for i, v in enumerate(confs): + if found_count == len(detections): + break + + for cls_id, query in queries.items(): + if found_count == len(detections): + break + + for q_id, (conf, det_idx) in enumerate(query): + if v[cls_id] == conf: + matches[det_idx] = i + query.pop(q_id) + found_count += 1 + break + + return matches + + +def process_outputs(inputs, outputs): + # inputs = model input; array or images; shape = (B, H, W, C) + # outputs = model output; shape = (1, 1, N, 7); N is the number of detected bounding boxes. + # det = [image_id, label(class id), conf, x_min, y_min, x_max, y_max] + # results = conversion result; [[ Annotation, ... ], ... ] + + results = [] + for input, detections in zip(inputs, outputs["detection_out"]): + + input_height, input_width = input.shape[:2] + + confs = outputs["Softmax_189/Softmax_"] + detections = detections[0] + + conf_ids = _match_confs(confs, detections) + + image_results = [] + for i, det in enumerate(detections): + image_id = int(det[0]) + label = int(det[1]) + conf = float(det[2]) + det_confs = confs[conf_ids[i]] + + if conf <= conf_thresh: + continue + + x = max(int(det[3] * input_width), 0) + y = max(int(det[4] * input_height), 0) + w = min(int(det[5] * input_width - x), input_width) + h = min(int(det[6] * input_height - y), input_height) + + image_results.append( + Bbox( + x, + y, + w, + h, + label=label, + attributes={ + "confidence": conf, + "confidences": list(map(float, det_confs)), + }, + ) + ) + + results.append(image_results) + + return results + + +def get_categories(): + # output categories - label map etc. + + label_categories = LabelCategories() + label_categories.add("vehicle") + label_categories.add("person") + label_categories.add("bike") + + return {AnnotationType.label: label_categories} diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_vehicle_detection_interp.py b/datumaro/plugins/openvino_interpreter_samples/ssd_vehicle_detection_interp.py new file mode 100644 index 0000000000..63e888bb46 --- /dev/null +++ b/datumaro/plugins/openvino_interpreter_samples/ssd_vehicle_detection_interp.py @@ -0,0 +1,93 @@ +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT + + +from datumaro.components.extractor import * + +conf_thresh = 0.02 + + +def _match_confs(confs, detections): + matches = [-1] * len(detections) + + queries = {} + for i, det in enumerate(detections): + queries.setdefault(int(det[1]), []).append((det[2], i)) + + found_count = 0 + for i, v in enumerate(confs): + if found_count == len(detections): + break + + for cls_id, query in queries.items(): + if found_count == len(detections): + break + + for q_id, (conf, det_idx) in enumerate(query): + if v[cls_id] == conf: + matches[det_idx] = i + query.pop(q_id) + found_count += 1 + break + + return matches + + +def process_outputs(inputs, outputs): + # inputs = model input; array or images; shape = (B, H, W, C) + # outputs = model output; shape = (1, 1, N, 7); N is the number of detected bounding boxes. + # det = [image_id, label(class id), conf, x_min, y_min, x_max, y_max] + # results = conversion result; [[ Annotation, ... ], ... ] + + results = [] + for input, detections in zip(inputs, outputs["detection_out"]): + + input_height, input_width = input.shape[:2] + + confs = outputs["Softmax_189/Softmax_"] + detections = detections[0] + + conf_ids = _match_confs(confs, detections) + + image_results = [] + for i, det in enumerate(detections): + image_id = int(det[0]) + label = int(det[1]) + conf = float(det[2]) + det_confs = confs[conf_ids[i]] + + if conf <= conf_thresh: + continue + + x = max(int(det[3] * input_width), 0) + y = max(int(det[4] * input_height), 0) + w = min(int(det[5] * input_width - x), input_width) + h = min(int(det[6] * input_height - y), input_height) + + image_results.append( + Bbox( + x, + y, + w, + h, + label=label, + attributes={ + "confidence": conf, + "confidences": list(map(float, det_confs)), + }, + ) + ) + + results.append(image_results) + + return results + + +def get_categories(): + # output categories - label map etc. + + label_categories = LabelCategories() + label_categories.add("vehicle") + + return {AnnotationType.label: label_categories} From adf7490be1cd23a72ff0de633126b95339b4e047 Mon Sep 17 00:00:00 2001 From: chuneuny <emily.chun@intel.com> Date: Fri, 12 Mar 2021 10:36:28 +0900 Subject: [PATCH 2/7] Change variable name from score to confidences --- datumaro/plugins/sampler/sampler.py | 6 +++--- tests/test_sampler.py | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/datumaro/plugins/sampler/sampler.py b/datumaro/plugins/sampler/sampler.py index 99791a8b0f..09768248ac 100644 --- a/datumaro/plugins/sampler/sampler.py +++ b/datumaro/plugins/sampler/sampler.py @@ -123,10 +123,10 @@ def _load_inference_from_subset(extractor, subset_name): raise Exception(f"Item {item.id} does not have annotations") for annotation in item.annotations: - if 'score' not in annotation.attributes: + if 'confidences' not in annotation.attributes: raise Exception(f"Item {item.id} - an annotation " - "does not have 'score' attribute") - probs = annotation.attributes['score'] + "does not have 'confidences' attribute") + probs = annotation.attributes['confidences'] infer_df['ImageID'].append(item.id) diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 31672e1b6d..5094b7c4d9 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -42,7 +42,7 @@ def _get_probs(out_range=False): return probs def _generate_classification_dataset(self, config, subset=None, - empty_score=False, out_range=False, no_attr=False, no_img=False): + empty_confidences=False, out_range=False, no_attr=False, no_img=False): probs = self._get_probs(out_range) if subset is None: self.subset = ["train", "val", "test"] @@ -56,11 +56,11 @@ def _generate_classification_dataset(self, config, subset=None, num_item = config[label] label_cat.add(label, attributes=None) for _ in range(num_item): - score = probs[idx] + confidences = probs[idx] idx += 1 - if empty_score: - score = [] - attr = {"score": score} + if empty_confidences: + confidences = [] + attr = {"confidences": confidences} if no_attr: attr = {} img = Image(path=f"test/dataset/{idx}.jpg", size=(90, 90)) @@ -341,7 +341,7 @@ def test_sampler_gives_error(self): data_df["ImagePath"].append(data.image.path) for annotation in data.annotations: - probs = annotation.attributes["score"] + probs = annotation.attributes["confidences"] infer_df["ImageID"].append(data.id) for prob_idx, prob in enumerate(probs): @@ -368,7 +368,7 @@ def test_sampler_gives_error(self): data_df["ImagePath"].append(data.image.path) for annotation in data.annotations: - probs = annotation.attributes["score"] + probs = annotation.attributes["confidences"] for prob_idx, prob in enumerate(probs): infer_df[f"ClassProbability{prob_idx+1}"].append(prob) @@ -401,14 +401,14 @@ def test_sampler_get_invalid_data(self): result = iter(result) next(result) - with self.subTest("Dataset without Score (Probability)"): + with self.subTest("Dataset without confidences (Probability)"): config = { "label1": 10, "label2": 10, "label3": 10, } - source = self._generate_classification_dataset(config, empty_score=True) + source = self._generate_classification_dataset(config, empty_confidences=True) with self.assertRaisesRegex(Exception, "ClassProbability"): result = Sampler( source, @@ -431,7 +431,7 @@ def test_sampler_get_invalid_data(self): } source = self._generate_classification_dataset( - config, empty_score=False, out_range=True + config, empty_confidences=False, out_range=True ) with self.assertRaisesRegex(Exception, "Invalid data"): result = Sampler( @@ -447,7 +447,7 @@ def test_sampler_get_invalid_data(self): result = iter(result) next(result) - with self.subTest("No Score Attribute Data"): + with self.subTest("No confidences Attribute Data"): config = { "label1": 10, "label2": 10, @@ -455,7 +455,7 @@ def test_sampler_get_invalid_data(self): } source = self._generate_classification_dataset(config, no_attr=True) - with self.assertRaisesRegex(Exception, "does not have 'score'"): + with self.assertRaisesRegex(Exception, "does not have 'confidences'"): result = Sampler( source, algorithm="entropy", From ec0a40505da720ab0ff0cc82c11540d14e9ddf4a Mon Sep 17 00:00:00 2001 From: chuneuny <emily.chun@intel.com> Date: Fri, 12 Mar 2021 11:07:29 +0900 Subject: [PATCH 3/7] Fix wrong path --- .../openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py | 2 +- .../ssd_mobilenet_coco_detection_interp.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py b/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py index 9f7ccb6803..2cb7ca0425 100644 --- a/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py +++ b/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py @@ -31,7 +31,7 @@ def get_categories(): label_categories = LabelCategories() with open( - "datumaro/plugins/openvino/interpreters/imagenet.class", "r" + "imagenet.class", "r" ) as file: for line in file.readlines(): label = line.strip() diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py b/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py index d0f3e51548..06623f3b7b 100644 --- a/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py +++ b/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py @@ -93,7 +93,7 @@ def get_categories(): label_categories = LabelCategories() with open( - "datumaro/plugins/openvino/interpreters/coco.class", "r" + "coco.class", "r" ) as file: for line in file.readlines(): label = line.strip() From 1021724c231b73a8cb5a21d6c84c162c5ff6f644 Mon Sep 17 00:00:00 2001 From: chuneuny <emily.chun@intel.com> Date: Mon, 15 Mar 2021 18:14:36 +0900 Subject: [PATCH 4/7] Move openvino_interpreter_samples into openvino/samples and renaming openvino_launcher.py into openvino/launcher.py. --- .../README.md | 42 +++++++++++++++++-- datumaro/plugins/openvino/__init__.py | 0 .../launcher.py} | 0 .../samples}/coco.class | 0 .../samples}/imagenet.class | 0 .../samples}/mobilenet_v2_pytorch_interp.py | 2 +- .../samples}/ssd_face_detection_interp.py | 0 .../ssd_mobilenet_coco_detection_interp.py | 2 +- .../samples}/ssd_person_detection_interp.py | 0 ...sd_person_vehicle_bike_detection_interp.py | 0 .../samples}/ssd_vehicle_detection_interp.py | 0 11 files changed, 41 insertions(+), 5 deletions(-) rename datumaro/plugins/{openvino_interpreter_samples => openvino}/README.md (53%) create mode 100644 datumaro/plugins/openvino/__init__.py rename datumaro/plugins/{openvino_launcher.py => openvino/launcher.py} (100%) rename datumaro/plugins/{openvino_interpreter_samples => openvino/samples}/coco.class (100%) rename datumaro/plugins/{openvino_interpreter_samples => openvino/samples}/imagenet.class (100%) rename datumaro/plugins/{openvino_interpreter_samples => openvino/samples}/mobilenet_v2_pytorch_interp.py (96%) rename datumaro/plugins/{openvino_interpreter_samples => openvino/samples}/ssd_face_detection_interp.py (100%) rename datumaro/plugins/{openvino_interpreter_samples => openvino/samples}/ssd_mobilenet_coco_detection_interp.py (98%) rename datumaro/plugins/{openvino_interpreter_samples => openvino/samples}/ssd_person_detection_interp.py (100%) rename datumaro/plugins/{openvino_interpreter_samples => openvino/samples}/ssd_person_vehicle_bike_detection_interp.py (100%) rename datumaro/plugins/{openvino_interpreter_samples => openvino/samples}/ssd_vehicle_detection_interp.py (100%) diff --git a/datumaro/plugins/openvino_interpreter_samples/README.md b/datumaro/plugins/openvino/README.md similarity index 53% rename from datumaro/plugins/openvino_interpreter_samples/README.md rename to datumaro/plugins/openvino/README.md index ca56cb261f..a85c96d7e1 100644 --- a/datumaro/plugins/openvino_interpreter_samples/README.md +++ b/datumaro/plugins/openvino/README.md @@ -21,19 +21,55 @@ Interpreter samples to parse OpenVINO inference outputs. - Public Pre-Trained Models(OMZ) - Classification - mobilenet-v2-pytorch (https://docs.openvinotoolkit.org/latest/omz_models_public_mobilenet_v2_pytorch_mobilenet_v2_pytorch.html) + - Object Detection - ssd_mobilenet_v1_coco (https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v1_coco_ssd_mobilenet_v1_coco.html) - ssd_mobilenet_v2_coco (https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v2_coco_ssd_mobilenet_v2_coco.html) ## Model download -- Prerequisites: OpenVINO (For installation, please see https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html) -- To download OpenVINO models, please see https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html +- Prerequisites + - OpenVINO (To install OpenVINO, please see https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html) + - OpenVINO models (To download OpenVINO models, please go https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html) + - VOCdevkit dataset (To download VOC2012 dataset, please go http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#devkit) ```bash - # cd <openvino_directory>/deployment_tools/open_model_zoo/tools/downloader + # cd <openvino_dir>/deployment_tools/open_model_zoo/tools/downloader # ./downloader.py --name <model_name> # # Examples cd /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader ./downloader.py --name face-detection-0200 + ``` + +## Model inference +- Prerequisites: + - Put the models downloaded in <datumaro_root_dir>/datumaro/plugins/openvino/models + - Put the VOCdevkit dataset downloaded in <datumaro_root_dir> + +- To run the inference with OpenVINO models and the interpreter samples, please follow the instructions below. + + ```bash + # . <openvino_dir>/bin/setupvars.sh + # cd <datumaro_root_dir>/datumaro/plugins/openvino/ + # datum create -o <proj_dir> + # datum model add -l <launcher> -p <proj_dir> --copy -- -d <path_to_xml> -w <path_to_bin> -i <path_to_interpreter_script> + # datum add path -p <proj_dir> -f <format> <path_to_dataset> + # datum model run -p <proj_dir> -m model-0 + # + # Examples + # Detection> ssd_mobilenet_v2_coco + . /opt/intel/openvino_2021/bin/setupvars.sh + cd /home/cvalgo/workspace/datumaro/datumaro/plugins/openvino/ + datum create -o proj_ssd_mobilenet_v2_coco_detection + datum model add -l openvino -p proj_ssd_mobilenet_v2_coco_detection --copy -- --output-layers=do_ExpandDims_conf/sigmoid -d model/ssd_mobilenet_v2_coco.xml -w model/ssd_mobilenet_v2_coco.bin -i samples/ssd_mobilenet_coco_detection_interp.py + datum add path -p proj_ssd_mobilenet_v2_coco_detection -f voc /home/cvalgo/workspace/datumaro/VOCdevkit + datum model run -p proj_ssd_mobilenet_v2_coco_detection -m model-0 + + # Classification> mobilenet-v2-pytorch + . /opt/intel/openvino_2021/bin/setupvars.sh + cd /home/cvalgo/workspace/datumaro/datumaro/plugins/openvino/ + datum create -o proj_mobilenet_v2_classification + datum model add -l openvino -p proj_mobilenet_v2_classification --copy -- -d model/mobilenet-v2-pytorch.xml -w model/mobilenet-v2-pytorch.bin -i samples/mobilenet_v2_pytorch_interp.py + datum add path -p proj_mobilenet_v2_classification -f voc /home/cvalgo/workspace/datumaro/VOCdevkit + datum model run -p proj_mobilenet_v2_classification -m model-0 ``` \ No newline at end of file diff --git a/datumaro/plugins/openvino/__init__.py b/datumaro/plugins/openvino/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/datumaro/plugins/openvino_launcher.py b/datumaro/plugins/openvino/launcher.py similarity index 100% rename from datumaro/plugins/openvino_launcher.py rename to datumaro/plugins/openvino/launcher.py diff --git a/datumaro/plugins/openvino_interpreter_samples/coco.class b/datumaro/plugins/openvino/samples/coco.class similarity index 100% rename from datumaro/plugins/openvino_interpreter_samples/coco.class rename to datumaro/plugins/openvino/samples/coco.class diff --git a/datumaro/plugins/openvino_interpreter_samples/imagenet.class b/datumaro/plugins/openvino/samples/imagenet.class similarity index 100% rename from datumaro/plugins/openvino_interpreter_samples/imagenet.class rename to datumaro/plugins/openvino/samples/imagenet.class diff --git a/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py b/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py similarity index 96% rename from datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py rename to datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py index 2cb7ca0425..da72e87745 100644 --- a/datumaro/plugins/openvino_interpreter_samples/mobilenet_v2_pytorch_interp.py +++ b/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py @@ -31,7 +31,7 @@ def get_categories(): label_categories = LabelCategories() with open( - "imagenet.class", "r" + "samples/imagenet.class", "r" ) as file: for line in file.readlines(): label = line.strip() diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_face_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py similarity index 100% rename from datumaro/plugins/openvino_interpreter_samples/ssd_face_detection_interp.py rename to datumaro/plugins/openvino/samples/ssd_face_detection_interp.py diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py similarity index 98% rename from datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py rename to datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py index 06623f3b7b..cbbbea1492 100644 --- a/datumaro/plugins/openvino_interpreter_samples/ssd_mobilenet_coco_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py @@ -93,7 +93,7 @@ def get_categories(): label_categories = LabelCategories() with open( - "coco.class", "r" + "samples/coco.class", "r" ) as file: for line in file.readlines(): label = line.strip() diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_person_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py similarity index 100% rename from datumaro/plugins/openvino_interpreter_samples/ssd_person_detection_interp.py rename to datumaro/plugins/openvino/samples/ssd_person_detection_interp.py diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_person_vehicle_bike_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py similarity index 100% rename from datumaro/plugins/openvino_interpreter_samples/ssd_person_vehicle_bike_detection_interp.py rename to datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py diff --git a/datumaro/plugins/openvino_interpreter_samples/ssd_vehicle_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py similarity index 100% rename from datumaro/plugins/openvino_interpreter_samples/ssd_vehicle_detection_interp.py rename to datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py From 6cefbfd384ef2ab8a3c9804e7c22128802b7be18 Mon Sep 17 00:00:00 2001 From: chuneuny <emily.chun@intel.com> Date: Tue, 16 Mar 2021 22:07:15 +0900 Subject: [PATCH 5/7] Update Maxim's comments --- datumaro/plugins/openvino/README.md | 72 ++++++++++--------- .../samples/mobilenet_v2_pytorch_interp.py | 6 +- .../samples/ssd_face_detection_interp.py | 14 +--- .../ssd_mobilenet_coco_detection_interp.py | 18 +---- .../samples/ssd_person_detection_interp.py | 14 +--- ...sd_person_vehicle_bike_detection_interp.py | 14 +--- .../samples/ssd_vehicle_detection_interp.py | 14 +--- datumaro/plugins/sampler/sampler.py | 6 +- docs/user_manual.md | 1 + tests/test_sampler.py | 24 +++---- 10 files changed, 64 insertions(+), 119 deletions(-) diff --git a/datumaro/plugins/openvino/README.md b/datumaro/plugins/openvino/README.md index a85c96d7e1..45a71c63fb 100644 --- a/datumaro/plugins/openvino/README.md +++ b/datumaro/plugins/openvino/README.md @@ -1,36 +1,43 @@ -# OpenVINO Inference Interpreter -Interpreter samples to parse OpenVINO inference outputs. +# OpenVINO™ Inference Interpreter +Interpreter samples to parse OpenVINO™ inference outputs. ## Models supported from interpreter samples +There are 5 SSD and 1 image classification interpreter samples. + +- 5 SSD interpreter samples support the following models. + - Intel Pre-trained Models > Object Detection + - [face-detection-0200](https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0200_description_face_detection_0200.html) + - [face-detection-0202](https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0202_description_face_detection_0202.html) + - [face-detection-0204](https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0204_description_face_detection_0204.html) + - [person-detection-0200](https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0200_description_person_detection_0200.html) + - [person-detection-0201](https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0201_description_person_detection_0201.html) + - [person-detection-0202](https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0202_description_person_detection_0202.html) + - [person-vehicle-bike-detection-2000](https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2000_description_person_vehicle_bike_detection_2000.html) + - [person-vehicle-bike-detection-2001](https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2001_description_person_vehicle_bike_detection_2001.html) + - [person-vehicle-bike-detection-2002](https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2002_description_person_vehicle_bike_detection_2002.html) + - [vehicle-detection-0200](https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0200_description_vehicle_detection_0200.html) + - [vehicle-detection-0201](https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0201_description_vehicle_detection_0201.html) + - [vehicle-detection-0202](https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0202_description_vehicle_detection_0202.html) + + - Public Pre-Trained Models(OMZ) > Object Detection + - [ssd_mobilenet_v1_coco](https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v1_coco_ssd_mobilenet_v1_coco.html) + - [ssd_mobilenet_v2_coco](https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v2_coco_ssd_mobilenet_v2_coco.html) -- Intel Pre-trained Models - - Object Detection - - face-detection-0200 (https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0200_description_face_detection_0200.html) - - face-detection-0202 (https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0202_description_face_detection_0202.html) - - face-detection-0204 (https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0204_description_face_detection_0204.html) - - person-detection-0200 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0200_description_person_detection_0200.html) - - person-detection-0201 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0201_description_person_detection_0201.html) - - person-detection-0202 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_detection_0202_description_person_detection_0202.html) - - person-vehicle-bike-detection-2000 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2000_description_person_vehicle_bike_detection_2000.html) - - person-vehicle-bike-detection-2001 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2001_description_person_vehicle_bike_detection_2001.html) - - person-vehicle-bike-detection-2002 (https://docs.openvinotoolkit.org/latest/omz_models_intel_person_vehicle_bike_detection_2002_description_person_vehicle_bike_detection_2002.html) - - vehicle-detection-0200 (https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0200_description_vehicle_detection_0200.html) - - vehicle-detection-0201 (https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0201_description_vehicle_detection_0201.html) - - vehicle-detection-0202 (https://docs.openvinotoolkit.org/latest/omz_models_intel_vehicle_detection_0202_description_vehicle_detection_0202.html) +- Image classification interpreter sample supports the following model. + - Public Pre-Trained Models(OMZ) > Classification + - [mobilenet-v2-pytorch](https://docs.openvinotoolkit.org/latest/omz_models_public_mobilenet_v2_pytorch_mobilenet_v2_pytorch.html) -- Public Pre-Trained Models(OMZ) - - Classification - - mobilenet-v2-pytorch (https://docs.openvinotoolkit.org/latest/omz_models_public_mobilenet_v2_pytorch_mobilenet_v2_pytorch.html) +You can find more OpenVINO™ Trained Models [here](https://docs.openvinotoolkit.org/latest/omz_models_intel_index.html) +To run the inference with OpenVINO™, the model format should be Intermediate Representation(IR). +For the Caffe/TensorFlow/MXNet/Kaldi/ONNX models, please see the [Model Conversion Instruction](https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_convert_model_Converting_Model.html) - - Object Detection - - ssd_mobilenet_v1_coco (https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v1_coco_ssd_mobilenet_v1_coco.html) - - ssd_mobilenet_v2_coco (https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v2_coco_ssd_mobilenet_v2_coco.html) +You need to implement your own interpreter samples to support the other OpenVINO™ Trained Models. ## Model download - Prerequisites - - OpenVINO (To install OpenVINO, please see https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html) - - OpenVINO models (To download OpenVINO models, please go https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html) - - VOCdevkit dataset (To download VOC2012 dataset, please go http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#devkit) + - OpenVINO™ (To install OpenVINO™, please see the [OpenVINO™ Installation Instruction](https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html) + - OpenVINO™ models (To download OpenVINO™ models, please see the [Model Downloader Instruction] https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html) + - PASCAL VOC 2012 dataset (To download VOC 2012 dataset, please go [VOC2012 download](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#devkit) ```bash # cd <openvino_dir>/deployment_tools/open_model_zoo/tools/downloader @@ -43,14 +50,15 @@ Interpreter samples to parse OpenVINO inference outputs. ## Model inference - Prerequisites: - - Put the models downloaded in <datumaro_root_dir>/datumaro/plugins/openvino/models - - Put the VOCdevkit dataset downloaded in <datumaro_root_dir> + - OpenVINO™ (To install OpenVINO™, please see the [OpenVINO™ Installation Instruction](https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html) + - Datumaro (To install Datumaro, please see the [User Manual](docs/user_manual.md) + - OpenVINO™ models (To download OpenVINO™ models, please see the [Model Downloader Instruction] https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html) + - PASCAL VOC 2012 dataset (To download VOC 2012 dataset, please go [VOC2012 download](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#devkit) -- To run the inference with OpenVINO models and the interpreter samples, please follow the instructions below. +- To run the inference with OpenVINO™ models and the interpreter samples, please follow the instructions below. ```bash - # . <openvino_dir>/bin/setupvars.sh - # cd <datumaro_root_dir>/datumaro/plugins/openvino/ + # <openvino_dir>/bin/setupvars.sh # datum create -o <proj_dir> # datum model add -l <launcher> -p <proj_dir> --copy -- -d <path_to_xml> -w <path_to_bin> -i <path_to_interpreter_script> # datum add path -p <proj_dir> -f <format> <path_to_dataset> @@ -58,7 +66,7 @@ Interpreter samples to parse OpenVINO inference outputs. # # Examples # Detection> ssd_mobilenet_v2_coco - . /opt/intel/openvino_2021/bin/setupvars.sh + /opt/intel/openvino_2021/bin/setupvars.sh cd /home/cvalgo/workspace/datumaro/datumaro/plugins/openvino/ datum create -o proj_ssd_mobilenet_v2_coco_detection datum model add -l openvino -p proj_ssd_mobilenet_v2_coco_detection --copy -- --output-layers=do_ExpandDims_conf/sigmoid -d model/ssd_mobilenet_v2_coco.xml -w model/ssd_mobilenet_v2_coco.bin -i samples/ssd_mobilenet_coco_detection_interp.py @@ -66,7 +74,7 @@ Interpreter samples to parse OpenVINO inference outputs. datum model run -p proj_ssd_mobilenet_v2_coco_detection -m model-0 # Classification> mobilenet-v2-pytorch - . /opt/intel/openvino_2021/bin/setupvars.sh + /opt/intel/openvino_2021/bin/setupvars.sh cd /home/cvalgo/workspace/datumaro/datumaro/plugins/openvino/ datum create -o proj_mobilenet_v2_classification datum model add -l openvino -p proj_mobilenet_v2_classification --copy -- -d model/mobilenet-v2-pytorch.xml -w model/mobilenet-v2-pytorch.bin -i samples/mobilenet_v2_pytorch_interp.py diff --git a/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py b/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py index da72e87745..65a1f3ccec 100644 --- a/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py +++ b/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py @@ -18,7 +18,7 @@ def process_outputs(inputs, outputs): image_results = [] output = softmax(output).tolist() label = output.index(max(output)) - image_results.append(Label(label=label, attributes={"confidences": output})) + image_results.append(Label(label=label, attributes={"scores": output})) results.append(image_results[:]) @@ -30,9 +30,7 @@ def get_categories(): label_categories = LabelCategories() - with open( - "samples/imagenet.class", "r" - ) as file: + with open("samples/imagenet.class", "r") as file: for line in file.readlines(): label = line.strip() label_categories.add(label) diff --git a/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py index 382aa64441..d08a1ada6b 100644 --- a/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py @@ -65,19 +65,7 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append( - Bbox( - x, - y, - w, - h, - label=label, - attributes={ - "confidence": conf, - "confidences": list(map(float, det_confs)), - }, - ) - ) + image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) results.append(image_results) diff --git a/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py index cbbbea1492..22cfaaf254 100644 --- a/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py @@ -68,19 +68,7 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append( - Bbox( - x, - y, - w, - h, - label=label, - attributes={ - "confidence": conf, - "confidences": list(map(float, det_confs)), - }, - ) - ) + image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) results.append(image_results) @@ -92,9 +80,7 @@ def get_categories(): label_categories = LabelCategories() - with open( - "samples/coco.class", "r" - ) as file: + with open("samples/coco.class", "r") as file: for line in file.readlines(): label = line.strip() label_categories.add(label) diff --git a/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py index 9b4e00d8c4..d12e8a5063 100644 --- a/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py @@ -65,19 +65,7 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append( - Bbox( - x, - y, - w, - h, - label=label, - attributes={ - "confidence": conf, - "confidences": list(map(float, det_confs)), - }, - ) - ) + image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) results.append(image_results) diff --git a/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py index 763180386d..f307f2a618 100644 --- a/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py @@ -65,19 +65,7 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append( - Bbox( - x, - y, - w, - h, - label=label, - attributes={ - "confidence": conf, - "confidences": list(map(float, det_confs)), - }, - ) - ) + image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) results.append(image_results) diff --git a/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py index 63e888bb46..c55dcd5a24 100644 --- a/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py @@ -65,19 +65,7 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append( - Bbox( - x, - y, - w, - h, - label=label, - attributes={ - "confidence": conf, - "confidences": list(map(float, det_confs)), - }, - ) - ) + image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) results.append(image_results) diff --git a/datumaro/plugins/sampler/sampler.py b/datumaro/plugins/sampler/sampler.py index 09768248ac..2fefa0e1dc 100644 --- a/datumaro/plugins/sampler/sampler.py +++ b/datumaro/plugins/sampler/sampler.py @@ -123,10 +123,10 @@ def _load_inference_from_subset(extractor, subset_name): raise Exception(f"Item {item.id} does not have annotations") for annotation in item.annotations: - if 'confidences' not in annotation.attributes: + if 'scores' not in annotation.attributes: raise Exception(f"Item {item.id} - an annotation " - "does not have 'confidences' attribute") - probs = annotation.attributes['confidences'] + "does not have 'scores' attribute") + probs = annotation.attributes['scores'] infer_df['ImageID'].append(item.id) diff --git a/docs/user_manual.md b/docs/user_manual.md index 99eb220523..29af84fa99 100644 --- a/docs/user_manual.md +++ b/docs/user_manual.md @@ -850,6 +850,7 @@ datum model add \ ``` Interpretation script for an OpenVINO detection model (`convert.py`): +You can find OpenVINO™ model interpreter samples in datumaro/plugins/openvino/samples. [Instruction](datumaro/plugins/openvino/README.md) ``` python from datumaro.components.extractor import * diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 5094b7c4d9..3f3d316d28 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -42,7 +42,7 @@ def _get_probs(out_range=False): return probs def _generate_classification_dataset(self, config, subset=None, - empty_confidences=False, out_range=False, no_attr=False, no_img=False): + empty_scores=False, out_range=False, no_attr=False, no_img=False): probs = self._get_probs(out_range) if subset is None: self.subset = ["train", "val", "test"] @@ -56,11 +56,11 @@ def _generate_classification_dataset(self, config, subset=None, num_item = config[label] label_cat.add(label, attributes=None) for _ in range(num_item): - confidences = probs[idx] + scores = probs[idx] idx += 1 - if empty_confidences: - confidences = [] - attr = {"confidences": confidences} + if empty_scores: + scores = [] + attr = {"scores": scores} if no_attr: attr = {} img = Image(path=f"test/dataset/{idx}.jpg", size=(90, 90)) @@ -341,7 +341,7 @@ def test_sampler_gives_error(self): data_df["ImagePath"].append(data.image.path) for annotation in data.annotations: - probs = annotation.attributes["confidences"] + probs = annotation.attributes["scores"] infer_df["ImageID"].append(data.id) for prob_idx, prob in enumerate(probs): @@ -368,7 +368,7 @@ def test_sampler_gives_error(self): data_df["ImagePath"].append(data.image.path) for annotation in data.annotations: - probs = annotation.attributes["confidences"] + probs = annotation.attributes["scores"] for prob_idx, prob in enumerate(probs): infer_df[f"ClassProbability{prob_idx+1}"].append(prob) @@ -401,14 +401,14 @@ def test_sampler_get_invalid_data(self): result = iter(result) next(result) - with self.subTest("Dataset without confidences (Probability)"): + with self.subTest("Dataset without Scores (Probability)"): config = { "label1": 10, "label2": 10, "label3": 10, } - source = self._generate_classification_dataset(config, empty_confidences=True) + source = self._generate_classification_dataset(config, empty_scores=True) with self.assertRaisesRegex(Exception, "ClassProbability"): result = Sampler( source, @@ -431,7 +431,7 @@ def test_sampler_get_invalid_data(self): } source = self._generate_classification_dataset( - config, empty_confidences=False, out_range=True + config, empty_scores=False, out_range=True ) with self.assertRaisesRegex(Exception, "Invalid data"): result = Sampler( @@ -447,7 +447,7 @@ def test_sampler_get_invalid_data(self): result = iter(result) next(result) - with self.subTest("No confidences Attribute Data"): + with self.subTest("No Scores Attribute Data"): config = { "label1": 10, "label2": 10, @@ -455,7 +455,7 @@ def test_sampler_get_invalid_data(self): } source = self._generate_classification_dataset(config, no_attr=True) - with self.assertRaisesRegex(Exception, "does not have 'confidences'"): + with self.assertRaisesRegex(Exception, "does not have 'scores'"): result = Sampler( source, algorithm="entropy", From 5dc37446cd5fa626ab2fae7792762e21dabd2656 Mon Sep 17 00:00:00 2001 From: chuneuny <emily.chun@intel.com> Date: Wed, 17 Mar 2021 10:02:21 +0900 Subject: [PATCH 6/7] Update Maxim's comments --- datumaro/plugins/openvino/README.md | 47 +++++++++++-------- .../samples/mobilenet_v2_pytorch_interp.py | 2 +- .../samples/ssd_face_detection_interp.py | 6 ++- .../ssd_mobilenet_coco_detection_interp.py | 6 ++- .../samples/ssd_person_detection_interp.py | 6 ++- ...sd_person_vehicle_bike_detection_interp.py | 6 ++- .../samples/ssd_vehicle_detection_interp.py | 6 ++- 7 files changed, 48 insertions(+), 31 deletions(-) diff --git a/datumaro/plugins/openvino/README.md b/datumaro/plugins/openvino/README.md index 45a71c63fb..a99d9404ef 100644 --- a/datumaro/plugins/openvino/README.md +++ b/datumaro/plugins/openvino/README.md @@ -2,9 +2,9 @@ Interpreter samples to parse OpenVINO™ inference outputs. ## Models supported from interpreter samples -There are 5 SSD and 1 image classification interpreter samples. +There are detection and image classification examples. -- 5 SSD interpreter samples support the following models. +- Detection (SSD-based) - Intel Pre-trained Models > Object Detection - [face-detection-0200](https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0200_description_face_detection_0200.html) - [face-detection-0202](https://docs.openvinotoolkit.org/latest/omz_models_intel_face_detection_0202_description_face_detection_0202.html) @@ -23,7 +23,7 @@ There are 5 SSD and 1 image classification interpreter samples. - [ssd_mobilenet_v1_coco](https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v1_coco_ssd_mobilenet_v1_coco.html) - [ssd_mobilenet_v2_coco](https://docs.openvinotoolkit.org/latest/omz_models_public_ssd_mobilenet_v2_coco_ssd_mobilenet_v2_coco.html) -- Image classification interpreter sample supports the following model. +- Image Classification - Public Pre-Trained Models(OMZ) > Classification - [mobilenet-v2-pytorch](https://docs.openvinotoolkit.org/latest/omz_models_public_mobilenet_v2_pytorch_mobilenet_v2_pytorch.html) @@ -35,30 +35,30 @@ You need to implement your own interpreter samples to support the other OpenVINO ## Model download - Prerequisites - - OpenVINO™ (To install OpenVINO™, please see the [OpenVINO™ Installation Instruction](https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html) - - OpenVINO™ models (To download OpenVINO™ models, please see the [Model Downloader Instruction] https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html) - - PASCAL VOC 2012 dataset (To download VOC 2012 dataset, please go [VOC2012 download](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#devkit) + - OpenVINO™ (To install OpenVINO™, please see the [OpenVINO™ Installation Instruction](https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html)) + - OpenVINO™ models (To download OpenVINO™ models, please see the [Model Downloader Instruction](https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html)) + - PASCAL VOC 2012 dataset (To download VOC 2012 dataset, please go [VOC2012 download](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#devkit)) ```bash # cd <openvino_dir>/deployment_tools/open_model_zoo/tools/downloader # ./downloader.py --name <model_name> # # Examples - cd /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader + cd /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader ./downloader.py --name face-detection-0200 ``` ## Model inference - Prerequisites: - - OpenVINO™ (To install OpenVINO™, please see the [OpenVINO™ Installation Instruction](https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html) - - Datumaro (To install Datumaro, please see the [User Manual](docs/user_manual.md) - - OpenVINO™ models (To download OpenVINO™ models, please see the [Model Downloader Instruction] https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html) - - PASCAL VOC 2012 dataset (To download VOC 2012 dataset, please go [VOC2012 download](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#devkit) + - OpenVINO™ (To install OpenVINO™, please see the [OpenVINO™ Installation Instruction](https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html)) + - Datumaro (To install Datumaro, please see the [User Manual](docs/user_manual.md)) + - OpenVINO™ models (To download OpenVINO™ models, please see the [Model Downloader Instruction](https://docs.openvinotoolkit.org/latest/omz_tools_downloader_README.html)) + - PASCAL VOC 2012 dataset (To download VOC 2012 dataset, please go [VOC2012 download](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#devkit)) - To run the inference with OpenVINO™ models and the interpreter samples, please follow the instructions below. ```bash - # <openvino_dir>/bin/setupvars.sh + # source <openvino_dir>/bin/setupvars.sh # datum create -o <proj_dir> # datum model add -l <launcher> -p <proj_dir> --copy -- -d <path_to_xml> -w <path_to_bin> -i <path_to_interpreter_script> # datum add path -p <proj_dir> -f <format> <path_to_dataset> @@ -66,18 +66,25 @@ You need to implement your own interpreter samples to support the other OpenVINO # # Examples # Detection> ssd_mobilenet_v2_coco - /opt/intel/openvino_2021/bin/setupvars.sh - cd /home/cvalgo/workspace/datumaro/datumaro/plugins/openvino/ + source /opt/intel/openvino/bin/setupvars.sh + cd datumaro/plugins/openvino datum create -o proj_ssd_mobilenet_v2_coco_detection - datum model add -l openvino -p proj_ssd_mobilenet_v2_coco_detection --copy -- --output-layers=do_ExpandDims_conf/sigmoid -d model/ssd_mobilenet_v2_coco.xml -w model/ssd_mobilenet_v2_coco.bin -i samples/ssd_mobilenet_coco_detection_interp.py - datum add path -p proj_ssd_mobilenet_v2_coco_detection -f voc /home/cvalgo/workspace/datumaro/VOCdevkit + datum model add -l openvino -p proj_ssd_mobilenet_v2_coco_detection --copy -- \ + --output-layers=do_ExpandDims_conf/sigmoid \ + -d model/ssd_mobilenet_v2_coco.xml \ + -w model/ssd_mobilenet_v2_coco.bin \ + -i samples/ssd_mobilenet_coco_detection_interp.py + datum add path -p proj_ssd_mobilenet_v2_coco_detection -f voc VOCdevkit/ datum model run -p proj_ssd_mobilenet_v2_coco_detection -m model-0 # Classification> mobilenet-v2-pytorch - /opt/intel/openvino_2021/bin/setupvars.sh - cd /home/cvalgo/workspace/datumaro/datumaro/plugins/openvino/ + source /opt/intel/openvino/bin/setupvars.sh + cd datumaro/plugins/openvino datum create -o proj_mobilenet_v2_classification - datum model add -l openvino -p proj_mobilenet_v2_classification --copy -- -d model/mobilenet-v2-pytorch.xml -w model/mobilenet-v2-pytorch.bin -i samples/mobilenet_v2_pytorch_interp.py - datum add path -p proj_mobilenet_v2_classification -f voc /home/cvalgo/workspace/datumaro/VOCdevkit + datum model add -l openvino -p proj_mobilenet_v2_classification --copy -- \ + -d model/mobilenet-v2-pytorch.xml \ + -w model/mobilenet-v2-pytorch.bin \ + -i samples/mobilenet_v2_pytorch_interp.py + datum add path -p proj_mobilenet_v2_classification -f voc VOCdevkit/ datum model run -p proj_mobilenet_v2_classification -m model-0 ``` \ No newline at end of file diff --git a/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py b/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py index 65a1f3ccec..43ce43fd21 100644 --- a/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py +++ b/datumaro/plugins/openvino/samples/mobilenet_v2_pytorch_interp.py @@ -20,7 +20,7 @@ def process_outputs(inputs, outputs): label = output.index(max(output)) image_results.append(Label(label=label, attributes={"scores": output})) - results.append(image_results[:]) + results.append(image_results) return results diff --git a/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py index d08a1ada6b..abb4604f8d 100644 --- a/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_face_detection_interp.py @@ -65,8 +65,10 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) - + image_results.append(Bbox(x, y, w, h, label=label, + attributes={ 'score': conf, 'scores': list(map(float, det_confs)) } + )) + results.append(image_results) return results diff --git a/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py index 22cfaaf254..3b3e5de252 100644 --- a/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_mobilenet_coco_detection_interp.py @@ -68,8 +68,10 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) - + image_results.append(Bbox(x, y, w, h, label=label, + attributes={ 'score': conf, 'scores': list(map(float, det_confs)) } + )) + results.append(image_results) return results diff --git a/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py index d12e8a5063..3888944df4 100644 --- a/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_person_detection_interp.py @@ -65,8 +65,10 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) - + image_results.append(Bbox(x, y, w, h, label=label, + attributes={ 'score': conf, 'scores': list(map(float, det_confs)) } + )) + results.append(image_results) return results diff --git a/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py index f307f2a618..a2de43dd6d 100644 --- a/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_person_vehicle_bike_detection_interp.py @@ -65,8 +65,10 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) - + image_results.append(Bbox(x, y, w, h, label=label, + attributes={ 'score': conf, 'scores': list(map(float, det_confs)) } + )) + results.append(image_results) return results diff --git a/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py b/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py index c55dcd5a24..2866133542 100644 --- a/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py +++ b/datumaro/plugins/openvino/samples/ssd_vehicle_detection_interp.py @@ -65,8 +65,10 @@ def process_outputs(inputs, outputs): w = min(int(det[5] * input_width - x), input_width) h = min(int(det[6] * input_height - y), input_height) - image_results.append(Bbox(x, y, w, h, label=label, attributes={"score": conf, "scores": list(map(float, det_confs)),},)) - + image_results.append(Bbox(x, y, w, h, label=label, + attributes={ 'score': conf, 'scores': list(map(float, det_confs)) } + )) + results.append(image_results) return results From fab3782c52e15708ce905401fa10e540ad17b4e5 Mon Sep 17 00:00:00 2001 From: chuneuny <emily.chun@intel.com> Date: Wed, 17 Mar 2021 10:31:55 +0900 Subject: [PATCH 7/7] Update Maxim's comments --- datumaro/plugins/openvino/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datumaro/plugins/openvino/README.md b/datumaro/plugins/openvino/README.md index a99d9404ef..a8f37d3ef9 100644 --- a/datumaro/plugins/openvino/README.md +++ b/datumaro/plugins/openvino/README.md @@ -59,10 +59,10 @@ You need to implement your own interpreter samples to support the other OpenVINO ```bash # source <openvino_dir>/bin/setupvars.sh - # datum create -o <proj_dir> - # datum model add -l <launcher> -p <proj_dir> --copy -- -d <path_to_xml> -w <path_to_bin> -i <path_to_interpreter_script> - # datum add path -p <proj_dir> -f <format> <path_to_dataset> - # datum model run -p <proj_dir> -m model-0 + # datum create -o <proj_dir> + # datum model add -l <launcher> -p <proj_dir> --copy -- -d <path_to_xml> -w <path_to_bin> -i <path_to_interpreter_script> + # datum add path -p <proj_dir> -f <format> <path_to_dataset> + # datum model run -p <proj_dir> -m model-0 # # Examples # Detection> ssd_mobilenet_v2_coco