From cc826f3237dd2764226c2240f03dc5bfb90586aa Mon Sep 17 00:00:00 2001 From: Yuan Zhao Date: Wed, 30 Oct 2019 22:02:26 -0500 Subject: Subgraph: add a mobilenet v1 example - Using the TidlRunSubgraph() interface --- examples/mobilenet_subgraph/Makefile | 43 + examples/mobilenet_subgraph/imagenet_objects.json | 1005 +++++++++++++++++++++ examples/mobilenet_subgraph/main.cpp | 307 +++++++ examples/mobilenet_subgraph/subgraph0.cfg | 9 + 4 files changed, 1364 insertions(+) create mode 100644 examples/mobilenet_subgraph/Makefile create mode 100644 examples/mobilenet_subgraph/imagenet_objects.json create mode 100644 examples/mobilenet_subgraph/main.cpp create mode 100644 examples/mobilenet_subgraph/subgraph0.cfg diff --git a/examples/mobilenet_subgraph/Makefile b/examples/mobilenet_subgraph/Makefile new file mode 100644 index 0000000..aed396c --- /dev/null +++ b/examples/mobilenet_subgraph/Makefile @@ -0,0 +1,43 @@ +# Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com/ +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Texas Instruments Incorporated nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +EXE = imagenet + +include ../make.common + +LIBS += -lopencv_highgui -lopencv_imgcodecs -lopencv_videoio\ + -lopencv_imgproc -lopencv_core +LIBS += -ljson-c + +LIBS += -L$(TIDL_API_DIR) -ltidl_api -ltidl_imgutil + +SOURCES = main.cpp ../common/object_classes.cpp ../common/utils.cpp \ + ../common/video_utils.cpp + +$(EXE): $(HEADERS) $(SOURCES) + $(CXX) $(CXXFLAGS) $(SOURCES) \ + $(LDFLAGS) $(LIBS) -o $@ + diff --git a/examples/mobilenet_subgraph/imagenet_objects.json b/examples/mobilenet_subgraph/imagenet_objects.json new file mode 100644 index 0000000..7a5289b --- /dev/null +++ b/examples/mobilenet_subgraph/imagenet_objects.json @@ -0,0 +1,1005 @@ +{ + "network": "imagenet", + "objects": [ + { "label": "tench" }, + { "label": "goldfish" }, + { "label": "great_white_shark" }, + { "label": "tiger_shark" }, + { "label": "hammerhead" }, + { "label": "electric_ray" }, + { "label": "stingray" }, + { "label": "cock" }, + { "label": "hen" }, + { "label": "ostrich" }, + { "label": "brambling" }, + { "label": "goldfinch" }, + { "label": "house_finch" }, + { "label": "junco" }, + { "label": "indigo_bunting" }, + { "label": "robin" }, + { "label": "bulbul" }, + { "label": "jay" }, + { "label": "magpie" }, + { "label": "chickadee" }, + { "label": "water_ouzel" }, + { "label": "kite" }, + { "label": "bald_eagle" }, + { "label": "vulture" }, + { "label": "great_grey_owl" }, + { "label": "European_fire_salamander" }, + { "label": "common_newt" }, + { "label": "eft" }, + { "label": "spotted_salamander" }, + { "label": "axolotl" }, + { "label": "bullfrog" }, + { "label": "tree_frog" }, + { "label": "tailed_frog" }, + { "label": "loggerhead" }, + { "label": "leatherback_turtle" }, + { "label": "mud_turtle" }, + { "label": "terrapin" }, + { "label": "box_turtle" }, + { "label": "banded_gecko" }, + { "label": "common_iguana" }, + { "label": "American_chameleon" }, + { "label": "whiptail" }, + { "label": "agama" }, + { "label": "frilled_lizard" }, + { "label": "alligator_lizard" }, + { "label": "Gila_monster" }, + { "label": "green_lizard" }, + { "label": "African_chameleon" }, + { "label": "Komodo_dragon" }, + { "label": "African_crocodile" }, + { "label": "American_alligator" }, + { "label": "triceratops" }, + { "label": "thunder_snake" }, + { "label": "ringneck_snake" }, + { "label": "hognose_snake" }, + { "label": "green_snake" }, + { "label": "king_snake" }, + { "label": "garter_snake" }, + { "label": "water_snake" }, + { "label": "vine_snake" }, + { "label": "night_snake" }, + { "label": "boa_constrictor" }, + { "label": "rock_python" }, + { "label": "Indian_cobra" }, + { "label": "green_mamba" }, + { "label": "sea_snake" }, + { "label": "horned_viper" }, + { "label": "diamondback" }, + { "label": "sidewinder" }, + { "label": "trilobite" }, + { "label": "harvestman" }, + { "label": "scorpion" }, + { "label": "black_and_gold_garden_spider" }, + { "label": "barn_spider" }, + { "label": "garden_spider" }, + { "label": "black_widow" }, + { "label": "tarantula" }, + { "label": "wolf_spider" }, + { "label": "tick" }, + { "label": "centipede" }, + { "label": "black_grouse" }, + { "label": "ptarmigan" }, + { "label": "ruffed_grouse" }, + { "label": "prairie_chicken" }, + { "label": "peacock" }, + { "label": "quail" }, + { "label": "partridge" }, + { "label": "African_grey" }, + { "label": "macaw" }, + { "label": "sulphur-crested_cockatoo" }, + { "label": "lorikeet" }, + { "label": "coucal" }, + { "label": "bee_eater" }, + { "label": "hornbill" }, + { "label": "hummingbird" }, + { "label": "jacamar" }, + { "label": "toucan" }, + { "label": "drake" }, + { "label": "red-breasted_merganser" }, + { "label": "goose" }, + { "label": "black_swan" }, + { "label": "tusker" }, + { "label": "echidna" }, + { "label": "platypus" }, + { "label": "wallaby" }, + { "label": "koala" }, + { "label": "wombat" }, + { "label": "jellyfish" }, + { "label": "sea_anemone" }, + { "label": "brain_coral" }, + { "label": "flatworm" }, + { "label": "nematode" }, + { "label": "conch" }, + { "label": "snail" }, + { "label": "slug" }, + { "label": "sea_slug" }, + { "label": "chiton" }, + { "label": "chambered_nautilus" }, + { "label": "Dungeness_crab" }, + { "label": "rock_crab" }, + { "label": "fiddler_crab" }, + { "label": "king_crab" }, + { "label": "American_lobster" }, + { "label": "spiny_lobster" }, + { "label": "crayfish" }, + { "label": "hermit_crab" }, + { "label": "isopod" }, + { "label": "white_stork" }, + { "label": "black_stork" }, + { "label": "spoonbill" }, + { "label": "flamingo" }, + { "label": "little_blue_heron" }, + { "label": "American_egret" }, + { "label": "bittern" }, + { "label": "crane" }, + { "label": "limpkin" }, + { "label": "European_gallinule" }, + { "label": "American_coot" }, + { "label": "bustard" }, + { "label": "ruddy_turnstone" }, + { "label": "red-backed_sandpiper" }, + { "label": "redshank" }, + { "label": "dowitcher" }, + { "label": "oystercatcher" }, + { "label": "pelican" }, + { "label": "king_penguin" }, + { "label": "albatross" }, + { "label": "grey_whale" }, + { "label": "killer_whale" }, + { "label": "dugong" }, + { "label": "sea_lion" }, + { "label": "Chihuahua" }, + { "label": "Japanese_spaniel" }, + { "label": "Maltese_dog" }, + { "label": "Pekinese" }, + { "label": "Shih-Tzu" }, + { "label": "Blenheim_spaniel" }, + { "label": "papillon" }, + { "label": "toy_terrier" }, + { "label": "Rhodesian_ridgeback" }, + { "label": "Afghan_hound" }, + { "label": "basset" }, + { "label": "beagle" }, + { "label": "bloodhound" }, + { "label": "bluetick" }, + { "label": "black-and-tan_coonhound" }, + { "label": "Walker_hound" }, + { "label": "English_foxhound" }, + { "label": "redbone" }, + { "label": "borzoi" }, + { "label": "Irish_wolfhound" }, + { "label": "Italian_greyhound" }, + { "label": "whippet" }, + { "label": "Ibizan_hound" }, + { "label": "Norwegian_elkhound" }, + { "label": "otterhound" }, + { "label": "Saluki" }, + { "label": "Scottish_deerhound" }, + { "label": "Weimaraner" }, + { "label": "Staffordshire_bullterrier" }, + { "label": "American_Staffordshire_terrier" }, + { "label": "Bedlington_terrier" }, + { "label": "Border_terrier" }, + { "label": "Kerry_blue_terrier" }, + { "label": "Irish_terrier" }, + { "label": "Norfolk_terrier" }, + { "label": "Norwich_terrier" }, + { "label": "Yorkshire_terrier" }, + { "label": "wire-haired_fox_terrier" }, + { "label": "Lakeland_terrier" }, + { "label": "Sealyham_terrier" }, + { "label": "Airedale" }, + { "label": "cairn" }, + { "label": "Australian_terrier" }, + { "label": "Dandie_Dinmont" }, + { "label": "Boston_bull" }, + { "label": "miniature_schnauzer" }, + { "label": "giant_schnauzer" }, + { "label": "standard_schnauzer" }, + { "label": "Scotch_terrier" }, + { "label": "Tibetan_terrier" }, + { "label": "silky_terrier" }, + { "label": "soft-coated_wheaten_terrier" }, + { "label": "West_Highland_white_terrier" }, + { "label": "Lhasa" }, + { "label": "flat-coated_retriever" }, + { "label": "curly-coated_retriever" }, + { "label": "golden_retriever" }, + { "label": "Labrador_retriever" }, + { "label": "Chesapeake_Bay_retriever" }, + { "label": "German_short-haired_pointer" }, + { "label": "vizsla" }, + { "label": "English_setter" }, + { "label": "Irish_setter" }, + { "label": "Gordon_setter" }, + { "label": "Brittany_spaniel" }, + { "label": "clumber" }, + { "label": "English_springer" }, + { "label": "Welsh_springer_spaniel" }, + { "label": "cocker_spaniel" }, + { "label": "Sussex_spaniel" }, + { "label": "Irish_water_spaniel" }, + { "label": "kuvasz" }, + { "label": "schipperke" }, + { "label": "groenendael" }, + { "label": "malinois" }, + { "label": "briard" }, + { "label": "kelpie" }, + { "label": "komondor" }, + { "label": "Old_English_sheepdog" }, + { "label": "Shetland_sheepdog" }, + { "label": "collie" }, + { "label": "Border_collie" }, + { "label": "Bouvier_des_Flandres" }, + { "label": "Rottweiler" }, + { "label": "German_shepherd" }, + { "label": "Doberman" }, + { "label": "miniature_pinscher" }, + { "label": "Greater_Swiss_Mountain_dog" }, + { "label": "Bernese_mountain_dog" }, + { "label": "Appenzeller" }, + { "label": "EntleBucher" }, + { "label": "boxer" }, + { "label": "bull_mastiff" }, + { "label": "Tibetan_mastiff" }, + { "label": "French_bulldog" }, + { "label": "Great_Dane" }, + { "label": "Saint_Bernard" }, + { "label": "Eskimo_dog" }, + { "label": "malamute" }, + { "label": "Siberian_husky" }, + { "label": "dalmatian" }, + { "label": "affenpinscher" }, + { "label": "basenji" }, + { "label": "pug" }, + { "label": "Leonberg" }, + { "label": "Newfoundland" }, + { "label": "Great_Pyrenees" }, + { "label": "Samoyed" }, + { "label": "Pomeranian" }, + { "label": "chow" }, + { "label": "keeshond" }, + { "label": "Brabancon_griffon" }, + { "label": "Pembroke" }, + { "label": "Cardigan" }, + { "label": "toy_poodle" }, + { "label": "miniature_poodle" }, + { "label": "standard_poodle" }, + { "label": "Mexican_hairless" }, + { "label": "timber_wolf" }, + { "label": "white_wolf" }, + { "label": "red_wolf" }, + { "label": "coyote" }, + { "label": "dingo" }, + { "label": "dhole" }, + { "label": "African_hunting_dog" }, + { "label": "hyena" }, + { "label": "red_fox" }, + { "label": "kit_fox" }, + { "label": "Arctic_fox" }, + { "label": "grey_fox" }, + { "label": "tabby" }, + { "label": "tiger_cat" }, + { "label": "Persian_cat" }, + { "label": "Siamese_cat" }, + { "label": "Egyptian_cat" }, + { "label": "cougar" }, + { "label": "lynx" }, + { "label": "leopard" }, + { "label": "snow_leopard" }, + { "label": "jaguar" }, + { "label": "lion" }, + { "label": "tiger" }, + { "label": "cheetah" }, + { "label": "brown_bear" }, + { "label": "American_black_bear" }, + { "label": "ice_bear" }, + { "label": "sloth_bear" }, + { "label": "mongoose" }, + { "label": "meerkat" }, + { "label": "tiger_beetle" }, + { "label": "ladybug" }, + { "label": "ground_beetle" }, + { "label": "long-horned_beetle" }, + { "label": "leaf_beetle" }, + { "label": "dung_beetle" }, + { "label": "rhinoceros_beetle" }, + { "label": "weevil" }, + { "label": "fly" }, + { "label": "bee" }, + { "label": "ant" }, + { "label": "grasshopper" }, + { "label": "cricket" }, + { "label": "walking_stick" }, + { "label": "cockroach" }, + { "label": "mantis" }, + { "label": "cicada" }, + { "label": "leafhopper" }, + { "label": "lacewing" }, + { "label": "dragonfly" }, + { "label": "damselfly" }, + { "label": "admiral" }, + { "label": "ringlet" }, + { "label": "monarch" }, + { "label": "cabbage_butterfly" }, + { "label": "sulphur_butterfly" }, + { "label": "lycaenid" }, + { "label": "starfish" }, + { "label": "sea_urchin" }, + { "label": "sea_cucumber" }, + { "label": "wood_rabbit" }, + { "label": "hare" }, + { "label": "Angora" }, + { "label": "hamster" }, + { "label": "porcupine" }, + { "label": "fox_squirrel" }, + { "label": "marmot" }, + { "label": "beaver" }, + { "label": "guinea_pig" }, + { "label": "sorrel" }, + { "label": "zebra" }, + { "label": "hog" }, + { "label": "wild_boar" }, + { "label": "warthog" }, + { "label": "hippopotamus" }, + { "label": "ox" }, + { "label": "water_buffalo" }, + { "label": "bison" }, + { "label": "ram" }, + { "label": "bighorn" }, + { "label": "ibex" }, + { "label": "hartebeest" }, + { "label": "impala" }, + { "label": "gazelle" }, + { "label": "Arabian_camel" }, + { "label": "llama" }, + { "label": "weasel" }, + { "label": "mink" }, + { "label": "polecat" }, + { "label": "black-footed_ferret" }, + { "label": "otter" }, + { "label": "skunk" }, + { "label": "badger" }, + { "label": "armadillo" }, + { "label": "three-toed_sloth" }, + { "label": "orangutan" }, + { "label": "gorilla" }, + { "label": "chimpanzee" }, + { "label": "gibbon" }, + { "label": "siamang" }, + { "label": "guenon" }, + { "label": "patas" }, + { "label": "baboon" }, + { "label": "macaque" }, + { "label": "langur" }, + { "label": "colobus" }, + { "label": "proboscis_monkey" }, + { "label": "marmoset" }, + { "label": "capuchin" }, + { "label": "howler_monkey" }, + { "label": "titi" }, + { "label": "spider_monkey" }, + { "label": "squirrel_monkey" }, + { "label": "Madagascar_cat" }, + { "label": "indri" }, + { "label": "Indian_elephant" }, + { "label": "African_elephant" }, + { "label": "lesser_panda" }, + { "label": "giant_panda" }, + { "label": "barracouta" }, + { "label": "eel" }, + { "label": "coho" }, + { "label": "rock_beauty" }, + { "label": "anemone_fish" }, + { "label": "sturgeon" }, + { "label": "gar" }, + { "label": "lionfish" }, + { "label": "puffer" }, + { "label": "abacus" }, + { "label": "abaya" }, + { "label": "academic_gown" }, + { "label": "accordion" }, + { "label": "acoustic_guitar" }, + { "label": "aircraft_carrier" }, + { "label": "airliner" }, + { "label": "airship" }, + { "label": "altar" }, + { "label": "ambulance" }, + { "label": "amphibian" }, + { "label": "analog_clock" }, + { "label": "apiary" }, + { "label": "apron" }, + { "label": "ashcan" }, + { "label": "assault_rifle" }, + { "label": "backpack" }, + { "label": "bakery" }, + { "label": "balance_beam" }, + { "label": "balloon" }, + { "label": "ballpoint" }, + { "label": "Band_Aid" }, + { "label": "banjo" }, + { "label": "bannister" }, + { "label": "barbell" }, + { "label": "barber_chair" }, + { "label": "barbershop" }, + { "label": "barn" }, + { "label": "barometer" }, + { "label": "barrel" }, + { "label": "barrow" }, + { "label": "baseball" }, + { "label": "basketball" }, + { "label": "bassinet" }, + { "label": "bassoon" }, + { "label": "bathing_cap" }, + { "label": "bath_towel" }, + { "label": "bathtub" }, + { "label": "beach_wagon" }, + { "label": "beacon" }, + { "label": "beaker" }, + { "label": "bearskin" }, + { "label": "beer_bottle" }, + { "label": "beer_glass" }, + { "label": "bell_cote" }, + { "label": "bib" }, + { "label": "bicycle-built-for-two" }, + { "label": "bikini" }, + { "label": "binder" }, + { "label": "binoculars" }, + { "label": "birdhouse" }, + { "label": "boathouse" }, + { "label": "bobsled" }, + { "label": "bolo_tie" }, + { "label": "bonnet" }, + { "label": "bookcase" }, + { "label": "bookshop" }, + { "label": "bottlecap" }, + { "label": "bow" }, + { "label": "bow_tie" }, + { "label": "brass" }, + { "label": "brassiere" }, + { "label": "breakwater" }, + { "label": "breastplate" }, + { "label": "broom" }, + { "label": "bucket" }, + { "label": "buckle" }, + { "label": "bulletproof_vest" }, + { "label": "bullet_train" }, + { "label": "butcher_shop" }, + { "label": "cab" }, + { "label": "caldron" }, + { "label": "candle" }, + { "label": "cannon" }, + { "label": "canoe" }, + { "label": "can_opener" }, + { "label": "cardigan" }, + { "label": "car_mirror" }, + { "label": "carousel" }, + { "label": "carpenter's_kit" }, + { "label": "carton" }, + { "label": "car_wheel" }, + { "label": "cash_machine" }, + { "label": "cassette" }, + { "label": "cassette_player" }, + { "label": "castle" }, + { "label": "catamaran" }, + { "label": "CD_player" }, + { "label": "cello" }, + { "label": "cellular_telephone" }, + { "label": "chain" }, + { "label": "chainlink_fence" }, + { "label": "chain_mail" }, + { "label": "chain_saw" }, + { "label": "chest" }, + { "label": "chiffonier" }, + { "label": "chime" }, + { "label": "china_cabinet" }, + { "label": "Christmas_stocking" }, + { "label": "church" }, + { "label": "cinema" }, + { "label": "cleaver" }, + { "label": "cliff_dwelling" }, + { "label": "cloak" }, + { "label": "clog" }, + { "label": "cocktail_shaker" }, + { "label": "coffee_mug" }, + { "label": "coffeepot" }, + { "label": "coil" }, + { "label": "combination_lock" }, + { "label": "computer_keyboard" }, + { "label": "confectionery" }, + { "label": "container_ship" }, + { "label": "convertible" }, + { "label": "corkscrew" }, + { "label": "cornet" }, + { "label": "cowboy_boot" }, + { "label": "cowboy_hat" }, + { "label": "cradle" }, + { "label": "crane" }, + { "label": "crash_helmet" }, + { "label": "crate" }, + { "label": "crib" }, + { "label": "Crock_Pot" }, + { "label": "croquet_ball" }, + { "label": "crutch" }, + { "label": "cuirass" }, + { "label": "dam" }, + { "label": "desk" }, + { "label": "desktop_computer" }, + { "label": "dial_telephone" }, + { "label": "diaper" }, + { "label": "digital_clock" }, + { "label": "digital_watch" }, + { "label": "dining_table" }, + { "label": "dishrag" }, + { "label": "dishwasher" }, + { "label": "disk_brake" }, + { "label": "dock" }, + { "label": "dogsled" }, + { "label": "dome" }, + { "label": "doormat" }, + { "label": "drilling_platform" }, + { "label": "drum" }, + { "label": "drumstick" }, + { "label": "dumbbell" }, + { "label": "Dutch_oven" }, + { "label": "electric_fan" }, + { "label": "electric_guitar" }, + { "label": "electric_locomotive" }, + { "label": "entertainment_center" }, + { "label": "envelope" }, + { "label": "espresso_maker" }, + { "label": "face_powder" }, + { "label": "feather_boa" }, + { "label": "file" }, + { "label": "fireboat" }, + { "label": "fire_engine" }, + { "label": "fire_screen" }, + { "label": "flagpole" }, + { "label": "flute" }, + { "label": "folding_chair" }, + { "label": "football_helmet" }, + { "label": "forklift" }, + { "label": "fountain" }, + { "label": "fountain_pen" }, + { "label": "four-poster" }, + { "label": "freight_car" }, + { "label": "French_horn" }, + { "label": "frying_pan" }, + { "label": "fur_coat" }, + { "label": "garbage_truck" }, + { "label": "gasmask" }, + { "label": "gas_pump" }, + { "label": "goblet" }, + { "label": "go-kart" }, + { "label": "golf_ball" }, + { "label": "golfcart" }, + { "label": "gondola" }, + { "label": "gong" }, + { "label": "gown" }, + { "label": "grand_piano" }, + { "label": "greenhouse" }, + { "label": "grille" }, + { "label": "grocery_store" }, + { "label": "guillotine" }, + { "label": "hair_slide" }, + { "label": "hair_spray" }, + { "label": "half_track" }, + { "label": "hammer" }, + { "label": "hamper" }, + { "label": "hand_blower" }, + { "label": "hand-held_computer" }, + { "label": "handkerchief" }, + { "label": "hard_disc" }, + { "label": "harmonica" }, + { "label": "harp" }, + { "label": "harvester" }, + { "label": "hatchet" }, + { "label": "holster" }, + { "label": "home_theater" }, + { "label": "honeycomb" }, + { "label": "hook" }, + { "label": "hoopskirt" }, + { "label": "horizontal_bar" }, + { "label": "horse_cart" }, + { "label": "hourglass" }, + { "label": "iPod" }, + { "label": "iron" }, + { "label": "jack-o'-lantern" }, + { "label": "jean" }, + { "label": "jeep" }, + { "label": "jersey" }, + { "label": "jigsaw_puzzle" }, + { "label": "jinrikisha" }, + { "label": "joystick" }, + { "label": "kimono" }, + { "label": "knee_pad" }, + { "label": "knot" }, + { "label": "lab_coat" }, + { "label": "ladle" }, + { "label": "lampshade" }, + { "label": "laptop" }, + { "label": "lawn_mower" }, + { "label": "lens_cap" }, + { "label": "letter_opener" }, + { "label": "library" }, + { "label": "lifeboat" }, + { "label": "lighter" }, + { "label": "limousine" }, + { "label": "liner" }, + { "label": "lipstick" }, + { "label": "Loafer" }, + { "label": "lotion" }, + { "label": "loudspeaker" }, + { "label": "loupe" }, + { "label": "lumbermill" }, + { "label": "magnetic_compass" }, + { "label": "mailbag" }, + { "label": "mailbox" }, + { "label": "maillot" }, + { "label": "maillot" }, + { "label": "manhole_cover" }, + { "label": "maraca" }, + { "label": "marimba" }, + { "label": "mask" }, + { "label": "matchstick" }, + { "label": "maypole" }, + { "label": "maze" }, + { "label": "measuring_cup" }, + { "label": "medicine_chest" }, + { "label": "megalith" }, + { "label": "microphone" }, + { "label": "microwave" }, + { "label": "military_uniform" }, + { "label": "milk_can" }, + { "label": "minibus" }, + { "label": "miniskirt" }, + { "label": "minivan" }, + { "label": "missile" }, + { "label": "mitten" }, + { "label": "mixing_bowl" }, + { "label": "mobile_home" }, + { "label": "Model_T" }, + { "label": "modem" }, + { "label": "monastery" }, + { "label": "monitor" }, + { "label": "moped" }, + { "label": "mortar" }, + { "label": "mortarboard" }, + { "label": "mosque" }, + { "label": "mosquito_net" }, + { "label": "motor_scooter" }, + { "label": "mountain_bike" }, + { "label": "mountain_tent" }, + { "label": "mouse" }, + { "label": "mousetrap" }, + { "label": "moving_van" }, + { "label": "muzzle" }, + { "label": "nail" }, + { "label": "neck_brace" }, + { "label": "necklace" }, + { "label": "nipple" }, + { "label": "notebook" }, + { "label": "obelisk" }, + { "label": "oboe" }, + { "label": "ocarina" }, + { "label": "odometer" }, + { "label": "oil_filter" }, + { "label": "organ" }, + { "label": "oscilloscope" }, + { "label": "overskirt" }, + { "label": "oxcart" }, + { "label": "oxygen_mask" }, + { "label": "packet" }, + { "label": "paddle" }, + { "label": "paddlewheel" }, + { "label": "padlock" }, + { "label": "paintbrush" }, + { "label": "pajama" }, + { "label": "palace" }, + { "label": "panpipe" }, + { "label": "paper_towel" }, + { "label": "parachute" }, + { "label": "parallel_bars" }, + { "label": "park_bench" }, + { "label": "parking_meter" }, + { "label": "passenger_car" }, + { "label": "patio" }, + { "label": "pay-phone" }, + { "label": "pedestal" }, + { "label": "pencil_box" }, + { "label": "pencil_sharpener" }, + { "label": "perfume" }, + { "label": "Petri_dish" }, + { "label": "photocopier" }, + { "label": "pick" }, + { "label": "pickelhaube" }, + { "label": "picket_fence" }, + { "label": "pickup" }, + { "label": "pier" }, + { "label": "piggy_bank" }, + { "label": "pill_bottle" }, + { "label": "pillow" }, + { "label": "ping-pong_ball" }, + { "label": "pinwheel" }, + { "label": "pirate" }, + { "label": "pitcher" }, + { "label": "plane" }, + { "label": "planetarium" }, + { "label": "plastic_bag" }, + { "label": "plate_rack" }, + { "label": "plow" }, + { "label": "plunger" }, + { "label": "Polaroid_camera" }, + { "label": "pole" }, + { "label": "police_van" }, + { "label": "poncho" }, + { "label": "pool_table" }, + { "label": "pop_bottle" }, + { "label": "pot" }, + { "label": "potter's_wheel" }, + { "label": "power_drill" }, + { "label": "prayer_rug" }, + { "label": "printer" }, + { "label": "prison" }, + { "label": "projectile" }, + { "label": "projector" }, + { "label": "puck" }, + { "label": "punching_bag" }, + { "label": "purse" }, + { "label": "quill" }, + { "label": "quilt" }, + { "label": "racer" }, + { "label": "racket" }, + { "label": "radiator" }, + { "label": "radio" }, + { "label": "radio_telescope" }, + { "label": "rain_barrel" }, + { "label": "recreational_vehicle" }, + { "label": "reel" }, + { "label": "reflex_camera" }, + { "label": "refrigerator" }, + { "label": "remote_control" }, + { "label": "restaurant" }, + { "label": "revolver" }, + { "label": "rifle" }, + { "label": "rocking_chair" }, + { "label": "rotisserie" }, + { "label": "rubber_eraser" }, + { "label": "rugby_ball" }, + { "label": "rule" }, + { "label": "running_shoe" }, + { "label": "safe" }, + { "label": "safety_pin" }, + { "label": "saltshaker" }, + { "label": "sandal" }, + { "label": "sarong" }, + { "label": "sax" }, + { "label": "scabbard" }, + { "label": "scale" }, + { "label": "school_bus" }, + { "label": "schooner" }, + { "label": "scoreboard" }, + { "label": "screen" }, + { "label": "screw" }, + { "label": "screwdriver" }, + { "label": "seat_belt" }, + { "label": "sewing_machine" }, + { "label": "shield" }, + { "label": "shoe_shop" }, + { "label": "shoji" }, + { "label": "shopping_basket" }, + { "label": "shopping_cart" }, + { "label": "shovel" }, + { "label": "shower_cap" }, + { "label": "shower_curtain" }, + { "label": "ski" }, + { "label": "ski_mask" }, + { "label": "sleeping_bag" }, + { "label": "slide_rule" }, + { "label": "sliding_door" }, + { "label": "slot" }, + { "label": "snorkel" }, + { "label": "snowmobile" }, + { "label": "snowplow" }, + { "label": "soap_dispenser" }, + { "label": "soccer_ball" }, + { "label": "sock" }, + { "label": "solar_dish" }, + { "label": "sombrero" }, + { "label": "soup_bowl" }, + { "label": "space_bar" }, + { "label": "space_heater" }, + { "label": "space_shuttle" }, + { "label": "spatula" }, + { "label": "speedboat" }, + { "label": "spider_web" }, + { "label": "spindle" }, + { "label": "sports_car" }, + { "label": "spotlight" }, + { "label": "stage" }, + { "label": "steam_locomotive" }, + { "label": "steel_arch_bridge" }, + { "label": "steel_drum" }, + { "label": "stethoscope" }, + { "label": "stole" }, + { "label": "stone_wall" }, + { "label": "stopwatch" }, + { "label": "stove" }, + { "label": "strainer" }, + { "label": "streetcar" }, + { "label": "stretcher" }, + { "label": "studio_couch" }, + { "label": "stupa" }, + { "label": "submarine" }, + { "label": "suit" }, + { "label": "sundial" }, + { "label": "sunglass" }, + { "label": "sunglasses" }, + { "label": "sunscreen" }, + { "label": "suspension_bridge" }, + { "label": "swab" }, + { "label": "sweatshirt" }, + { "label": "swimming_trunks" }, + { "label": "swing" }, + { "label": "switch" }, + { "label": "syringe" }, + { "label": "table_lamp" }, + { "label": "tank" }, + { "label": "tape_player" }, + { "label": "teapot" }, + { "label": "teddy" }, + { "label": "television" }, + { "label": "tennis_ball" }, + { "label": "thatch" }, + { "label": "theater_curtain" }, + { "label": "thimble" }, + { "label": "thresher" }, + { "label": "throne" }, + { "label": "tile_roof" }, + { "label": "toaster" }, + { "label": "tobacco_shop" }, + { "label": "toilet_seat" }, + { "label": "torch" }, + { "label": "totem_pole" }, + { "label": "tow_truck" }, + { "label": "toyshop" }, + { "label": "tractor" }, + { "label": "trailer_truck" }, + { "label": "tray" }, + { "label": "trench_coat" }, + { "label": "tricycle" }, + { "label": "trimaran" }, + { "label": "tripod" }, + { "label": "triumphal_arch" }, + { "label": "trolleybus" }, + { "label": "trombone" }, + { "label": "tub" }, + { "label": "turnstile" }, + { "label": "typewriter_keyboard" }, + { "label": "umbrella" }, + { "label": "unicycle" }, + { "label": "upright" }, + { "label": "vacuum" }, + { "label": "vase" }, + { "label": "vault" }, + { "label": "velvet" }, + { "label": "vending_machine" }, + { "label": "vestment" }, + { "label": "viaduct" }, + { "label": "violin" }, + { "label": "volleyball" }, + { "label": "waffle_iron" }, + { "label": "wall_clock" }, + { "label": "wallet" }, + { "label": "wardrobe" }, + { "label": "warplane" }, + { "label": "washbasin" }, + { "label": "washer" }, + { "label": "water_bottle" }, + { "label": "water_jug" }, + { "label": "water_tower" }, + { "label": "whiskey_jug" }, + { "label": "whistle" }, + { "label": "wig" }, + { "label": "window_screen" }, + { "label": "window_shade" }, + { "label": "Windsor_tie" }, + { "label": "wine_bottle" }, + { "label": "wing" }, + { "label": "wok" }, + { "label": "wooden_spoon" }, + { "label": "wool" }, + { "label": "worm_fence" }, + { "label": "wreck" }, + { "label": "yawl" }, + { "label": "yurt" }, + { "label": "web_site" }, + { "label": "comic_book" }, + { "label": "crossword_puzzle" }, + { "label": "street_sign" }, + { "label": "traffic_light" }, + { "label": "book_jacket" }, + { "label": "menu" }, + { "label": "plate" }, + { "label": "guacamole" }, + { "label": "consomme" }, + { "label": "hot_pot" }, + { "label": "trifle" }, + { "label": "ice_cream" }, + { "label": "ice_lolly" }, + { "label": "French_loaf" }, + { "label": "bagel" }, + { "label": "pretzel" }, + { "label": "cheeseburger" }, + { "label": "hotdog" }, + { "label": "mashed_potato" }, + { "label": "head_cabbage" }, + { "label": "broccoli" }, + { "label": "cauliflower" }, + { "label": "zucchini" }, + { "label": "spaghetti_squash" }, + { "label": "acorn_squash" }, + { "label": "butternut_squash" }, + { "label": "cucumber" }, + { "label": "artichoke" }, + { "label": "bell_pepper" }, + { "label": "cardoon" }, + { "label": "mushroom" }, + { "label": "Granny_Smith" }, + { "label": "strawberry" }, + { "label": "orange" }, + { "label": "lemon" }, + { "label": "fig" }, + { "label": "pineapple" }, + { "label": "banana" }, + { "label": "jackfruit" }, + { "label": "custard_apple" }, + { "label": "pomegranate" }, + { "label": "hay" }, + { "label": "carbonara" }, + { "label": "chocolate_sauce" }, + { "label": "dough" }, + { "label": "meat_loaf" }, + { "label": "pizza" }, + { "label": "potpie" }, + { "label": "burrito" }, + { "label": "red_wine" }, + { "label": "espresso" }, + { "label": "cup" }, + { "label": "eggnog" }, + { "label": "alp" }, + { "label": "bubble" }, + { "label": "cliff" }, + { "label": "coral_reef" }, + { "label": "geyser" }, + { "label": "lakeside" }, + { "label": "promontory" }, + { "label": "sandbar" }, + { "label": "seashore" }, + { "label": "valley" }, + { "label": "volcano" }, + { "label": "ballplayer" }, + { "label": "groom" }, + { "label": "scuba_diver" }, + { "label": "rapeseed" }, + { "label": "daisy" }, + { "label": "yellow_lady's_slipper" }, + { "label": "corn" }, + { "label": "acorn" }, + { "label": "hip" }, + { "label": "buckeye" }, + { "label": "coral_fungus" }, + { "label": "agaric" }, + { "label": "gyromitra" }, + { "label": "stinkhorn" }, + { "label": "earthstar" }, + { "label": "hen-of-the-woods" }, + { "label": "bolete" }, + { "label": "ear" }, + { "label": "toilet_tissue" } + ] +} diff --git a/examples/mobilenet_subgraph/main.cpp b/examples/mobilenet_subgraph/main.cpp new file mode 100644 index 0000000..c5da647 --- /dev/null +++ b/examples/mobilenet_subgraph/main.cpp @@ -0,0 +1,307 @@ +/****************************************************************************** + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Texas Instruments Incorporated nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "executor.h" +#include "execution_object.h" +#include "execution_object_pipeline.h" +#include "subgraph_runtime.h" +#include "configuration.h" +#include "../common/object_classes.h" +#include "imgutil.h" +#include "../common/video_utils.h" + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/videoio.hpp" + +using namespace std; +using namespace tidl; +using namespace cv; + +#define NUM_VIDEO_FRAMES 300 +#define DEFAULT_CONFIG "j11_v2" +#define NUM_DEFAULT_INPUTS 1 +#define DEFAULT_OBJECT_CLASSES_LIST_FILE "imagenet_objects.json" +#define DEFAULT_OUTPUT_PROB_THRESHOLD 5 +const char *default_inputs[NUM_DEFAULT_INPUTS] = +{ + "../test/testvecs/input/objects/cat-pet-animal-domestic-104827.jpeg" +}; +std::unique_ptr object_classes; + +bool RunConfiguration(cmdline_opts_t& opts); +bool ReadFrame(const cmdline_opts_t& opts, VideoCapture &cap, float** inputs); +bool WriteFrameOutput(float *out, const cmdline_opts_t& opts); +void DisplayHelp(); + + +int main(int argc, char *argv[]) +{ + // Catch ctrl-c to ensure a clean exit + signal(SIGABRT, exit); + signal(SIGTERM, exit); + + // If there are no devices capable of offloading TIDL on the SoC, exit + uint32_t num_eves = Executor::GetNumDevices(DeviceType::EVE); + uint32_t num_dsps = Executor::GetNumDevices(DeviceType::DSP); + if (num_eves == 0 && num_dsps == 0) + { + cout << "TI DL not supported on this SoC." << endl; + return EXIT_SUCCESS; + } + + // Process arguments + cmdline_opts_t opts; + opts.config = DEFAULT_CONFIG; + opts.object_classes_list_file = DEFAULT_OBJECT_CLASSES_LIST_FILE; + opts.output_prob_threshold = DEFAULT_OUTPUT_PROB_THRESHOLD; + if (num_eves != 0) { opts.num_eves = 1; opts.num_dsps = 0; } + else { opts.num_eves = 0; opts.num_dsps = 1; } + if (! ProcessArgs(argc, argv, opts)) + { + DisplayHelp(); + exit(EXIT_SUCCESS); + } + assert(opts.num_dsps != 0 || opts.num_eves != 0); + if (opts.num_frames == 0) + opts.num_frames = (opts.is_camera_input || opts.is_video_input) ? + NUM_VIDEO_FRAMES : 1; + if (opts.input_file.empty()) + cout << "Input: " << default_inputs[0] << endl; + else + cout << "Input: " << opts.input_file << endl; + + // Get object classes list + object_classes = std::unique_ptr( + new ObjectClasses(opts.object_classes_list_file)); + if (object_classes->GetNumClasses() == 0) + { + cout << "No object classes defined for this config." << endl; + return EXIT_FAILURE; + } + + // Run network + bool status = RunConfiguration(opts); + if (!status) + { + cout << "imagenet FAILED" << endl; + return EXIT_FAILURE; + } + + cout << "imagenet PASSED" << endl; + return EXIT_SUCCESS; +} + +bool RunConfiguration(cmdline_opts_t& opts) +{ + bool status = true; + + // setup camera/video input/output + VideoCapture cap; + if (! SetVideoInputOutput(cap, opts, "ImageNet")) return false; + + try + { + float **inputs = new float *[1]; + inputs[0] = new float[1*3*224*224]; + float **outputs = new float *[1]; + outputs[0] = new float[1001]; + + for (int i = 0; i < 5; i ++) + { + chrono::time_point tloop0, tloop1; + tloop0 = chrono::steady_clock::now(); + + ReadFrame(opts, cap, inputs); + TidlRunSubgraph(1, 0, 1, 1, inputs, outputs); + WriteFrameOutput(outputs[0], opts); + + tloop1 = chrono::steady_clock::now(); + chrono::duration elapsed = tloop1 - tloop0; + cout << "Frame " << i + << " time (including read/write/opencv/print/etc): " + << setw(6) << setprecision(4) + << (elapsed.count() * 1000) << "ms" << endl; + } + + delete [] inputs[0]; + delete [] inputs; + delete [] outputs[0]; + delete [] outputs; + } + catch (tidl::Exception &e) + { + cerr << e.what() << endl; + status = false; + } + + return status; +} + + +bool ReadFrame(const cmdline_opts_t& opts, VideoCapture &cap, float** inputs) +{ + Configuration c; + c.inNumChannels = 3;; + c.inWidth = 224; + c.inHeight = 224; + c.preProcType = 2; + SubgraphDataConv in_conv{{true}, {128.0f}, {false}, {1,3,224,224}}; + + char* frame_buffer = new char[3*224*224]; + assert (frame_buffer != nullptr); + + Mat image; + if (! opts.is_camera_input && ! opts.is_video_input) + { + if (opts.input_file.empty()) + image = cv::imread(default_inputs[0], + CV_LOAD_IMAGE_COLOR); + else + image = cv::imread(opts.input_file, CV_LOAD_IMAGE_COLOR); + if (image.empty()) + { + cerr << "Unable to read input image" << endl; + return false; + } + } + else + { + Mat v_image; + if (! cap.grab()) return false; + if (! cap.retrieve(v_image)) return false; + int orig_width = v_image.cols; + int orig_height = v_image.rows; + // Crop camera/video input to center 256x256 input + if (orig_width > 256 && orig_height > 256) + { + image = Mat(v_image, Rect((orig_width-256)/2, (orig_height-256)/2, + 256, 256)); + } + else + image = v_image; + cv::imshow("ImageNet", image); + waitKey(2); + } + + // TI DL image preprocessing, into frame_buffer + bool status = imgutil::PreprocessImage(image, frame_buffer, c); + std::vector in_data_v{inputs[0]}; + in_conv.ScaleDequant((const uint8_t *)frame_buffer, in_data_v); + delete [] frame_buffer; + return status; +} + +// Display top 5 classified imagenet classes with probabilities 5% or higher +bool WriteFrameOutput(float *out, const cmdline_opts_t& opts) +{ + const int k = 5; + int out_size = 1001; + // Tensorflow trained network outputs 1001 probabilities, + // with 0-index being background, thus we need to subtract 1 when + // reporting classified object from 1000 categories + int background_offset = out_size == 1001 ? 1 : 0; + + // sort and get k largest values and corresponding indices + typedef pair val_index; + auto cmp = [](val_index &left, val_index &right) + { return left.first > right.first; }; + priority_queue, decltype(cmp)> queue(cmp); + // initialize priority queue with smallest value on top + for (int i = 0; i < k; i++) + queue.push(val_index(out[i], i)); + + // for rest output, if larger than current min, pop min, push new val + for (int i = k; i < out_size; i++) + { + if (out[i] > queue.top().first) + { + queue.pop(); + queue.push(val_index(out[i], i)); + } + } + + // output top k values in reverse order: largest val first + vector sorted; + while (! queue.empty()) + { + sorted.push_back(queue.top()); + queue.pop(); + } + + for (int i = k - 1; i >= 0; i--) + { + if (sorted[i].first * 100 < opts.output_prob_threshold) break; + int imagenet_index = sorted[i].second - background_offset; + cout << k-i << ": [" << imagenet_index << "] " + << object_classes->At(imagenet_index).label + << ", prob = " << setprecision(4) + << (sorted[i].first * 100) << "%" << endl; + } + + return true; +} + +void DisplayHelp() +{ + cout << + "Usage: imagenet\n" + " Will run imagenet network to predict top 5 object" + " classes for the input.\n Use -c to run a" + " different imagenet network. Default is j11_v2.\n" + "Optional arguments:\n" + " -c Valid configs: j11_bn, j11_prelu, j11_v2\n" + " -d Number of dsp cores to use\n" + " -e Number of eve cores to use\n" + " -i Path to the image file as input\n" + " -i camera Use camera as input\n" + " video input port: /dev/video\n" + " -i .{mp4,mov,avi} Use video file as input\n" + " -l Path to the object classes list file\n" + " -f Number of frames to process\n" + " -p Output probablity threshold in percentage\n" + " Default is 5 percent or higher.\n" + " -v Verbose output during execution\n" + " -h Help\n"; +} + diff --git a/examples/mobilenet_subgraph/subgraph0.cfg b/examples/mobilenet_subgraph/subgraph0.cfg new file mode 100644 index 0000000..17c20bf --- /dev/null +++ b/examples/mobilenet_subgraph/subgraph0.cfg @@ -0,0 +1,9 @@ +numFrames = 1 +preProcType = 2 +inData = "../test/testvecs/input/preproc_2_224x224.y" +outData = "./stats_tool_out.bin" +netBinFile = "../test/testvecs/config/tidl_models/tidl_net_mobilenet_1_224.bin" +paramsBinFile = "../test/testvecs/config/tidl_models/tidl_param_mobilenet_1_224.bin" +inWidth = 224 +inHeight = 224 +inNumChannels = 3 -- cgit v1.2.3-54-g00ecf