Add imagenet example to tinn
authorYuan Zhao <yuanzhao@ti.com>
Tue, 17 Apr 2018 22:00:28 +0000 (17:00 -0500)
committerYuan Zhao <yuanzhao@ti.com>
Tue, 24 Apr 2018 16:10:28 +0000 (11:10 -0500)
- MCT-963

29 files changed:
examples/imagenet/Makefile [new file with mode: 0644]
examples/imagenet/imagenet_classes.cpp [new file with mode: 0644]
examples/imagenet/imagenet_classes.h [new file with mode: 0644]
examples/imagenet/main.cpp [new file with mode: 0644]
examples/make.common [new file with mode: 0644]
examples/test/Makefile
examples/test/testvecs/config/infer/tidl_config_dense_1x1.txt
examples/test/testvecs/config/infer/tidl_config_inceptionNetv1.txt
examples/test/testvecs/config/infer/tidl_config_j11_bn.txt
examples/test/testvecs/config/infer/tidl_config_j11_cifar.txt
examples/test/testvecs/config/infer/tidl_config_j11_controlLayers.txt
examples/test/testvecs/config/infer/tidl_config_j11_prelu.txt
examples/test/testvecs/config/infer/tidl_config_j11_v2.txt
examples/test/testvecs/config/infer/tidl_config_jseg21.txt
examples/test/testvecs/config/infer/tidl_config_jseg21_tiscapes.txt
examples/test/testvecs/config/infer/tidl_config_mobileNet1.txt
examples/test/testvecs/config/infer/tidl_config_smallRoi.txt
examples/test/testvecs/config/infer/tidl_config_squeeze1_1.txt
examples/test/testvecs/input/airshow.jpg [new file with mode: 0644]
tinn_api/Makefile
tinn_api/dsp/Makefile
tinn_api/inc/configuration.h
tinn_api/inc/imgutil.h [new file with mode: 0644]
tinn_api/make.inc
tinn_api/src/configuration.cpp
tinn_api/src/configuration_parser.cpp
tinn_api/src/executor.cpp
tinn_api/src/imgutil.cpp [new file with mode: 0644]
tinn_api/src/ocl_device.cpp

diff --git a/examples/imagenet/Makefile b/examples/imagenet/Makefile
new file mode 100644 (file)
index 0000000..7359e20
--- /dev/null
@@ -0,0 +1,13 @@
+EXE = imagenet
+
+include ../make.common
+
+CXXFLAGS += $(shell pkg-config --cflags opencv)
+LIBS     += $(shell pkg-config --libs --static opencv)
+
+SOURCES = main.cpp imagenet_classes.cpp
+
+$(EXE): $(TINN_LIB) $(TINN_LIB_IMGUTIL) $(HEADERS) $(SOURCES)
+       $(CXX) $(CXXFLAGS) $(SOURCES) $(TINN_LIB) $(TINN_LIB_IMGUTIL) \
+           $(LDFLAGS) $(LIBS) -o $@
+
diff --git a/examples/imagenet/imagenet_classes.cpp b/examples/imagenet/imagenet_classes.cpp
new file mode 100644 (file)
index 0000000..abd5f33
--- /dev/null
@@ -0,0 +1,1032 @@
+/******************************************************************************
+ * 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 "imagenet_classes.h"
+
+std::string imagenet_classes[NUM_IMAGENET_CLASSES] = {
+"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",
+"crane",
+"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",
+"maillot",
+"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"
+};
diff --git a/examples/imagenet/imagenet_classes.h b/examples/imagenet/imagenet_classes.h
new file mode 100644 (file)
index 0000000..cfdfb33
--- /dev/null
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * 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 <string>
+
+#define NUM_IMAGENET_CLASSES  1000
+
+extern std::string imagenet_classes[NUM_IMAGENET_CLASSES];
+
diff --git a/examples/imagenet/main.cpp b/examples/imagenet/main.cpp
new file mode 100644 (file)
index 0000000..0aaf8d0
--- /dev/null
@@ -0,0 +1,410 @@
+/******************************************************************************
+ * 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 <signal.h>
+#include <getopt.h>
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <cassert>
+#include <string>
+#include <functional>
+#include <algorithm>
+#include <time.h>
+#include <unistd.h>
+
+#include <queue>
+#include <vector>
+
+#include "executor.h"
+#include "execution_object.h"
+#include "configuration.h"
+#include "imagenet_classes.h"
+#include "imgutil.h"
+
+#include "opencv2/core.hpp"
+#include "opencv2/imgproc.hpp"
+#include "opencv2/highgui.hpp"
+#include "opencv2/videoio.hpp"
+
+
+bool __TI_show_debug_ = false;
+
+using namespace tinn;
+using namespace tinn::imgutil;
+using namespace cv;
+
+#define NUM_VIDEO_FRAMES  100
+
+bool RunConfiguration(const std::string& config_file, int num_devices,
+                      DeviceType device_type, std::string& input_file);
+bool RunAllConfigurations(int32_t num_devices, DeviceType device_type);
+
+bool ReadFrame(ExecutionObject& eo, int frame_idx,
+               const Configuration& configuration, int num_frames,
+               std::string& image_file, VideoCapture &cap);
+
+bool WriteFrameOutput(const ExecutionObject &eo);
+
+static void ProcessArgs(int argc, char *argv[],
+                        std::string& config,
+                        int& num_devices,
+                        DeviceType& device_type,
+                        std::string& input_file);
+
+static void DisplayHelp();
+
+static double ms_diff(struct timespec &t0, struct timespec &t1)
+{ return (t1.tv_sec - t0.tv_sec) * 1e3 + (t1.tv_nsec - t0.tv_nsec) / 1e6; }
+
+
+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_dla = Executor::GetNumDevices(DeviceType::DLA);
+    uint32_t num_dsp = Executor::GetNumDevices(DeviceType::DSP);
+    if (num_dla == 0 && num_dsp == 0)
+    {
+        std::cout << "TI DL not supported on this SoC." << std::endl;
+        return EXIT_SUCCESS;
+    }
+
+    // Process arguments
+    chdir("../test");
+    std::string config      = "j11_v2";
+    std::string input_file  = "../test/testvecs/input/airshow.jpg";
+    int         num_devices = 1;
+    DeviceType  device_type = DeviceType::DLA;
+    ProcessArgs(argc, argv, config, num_devices, device_type, input_file);
+
+    std::cout << "Input: " << input_file << std::endl;
+    std::string config_file = "../test/testvecs/config/infer/tidl_config_"
+                              + config + ".txt";
+    bool status = RunConfiguration(config_file, num_devices, device_type,
+                                   input_file);
+
+    if (!status)
+    {
+        std::cout << "imagenet FAILED" << std::endl;
+        return EXIT_FAILURE;
+    }
+
+    std::cout << "imagenet PASSED" << std::endl;
+    return EXIT_SUCCESS;
+}
+
+bool RunConfiguration(const std::string& config_file, int num_devices,
+                      DeviceType device_type, std::string& input_file)
+{
+    DeviceIds ids;
+    for (int i = 0; i < num_devices; i++)
+        ids.insert(static_cast<DeviceId>(i));
+
+    // Read the TI DL configuration file
+    Configuration configuration;
+    bool status = configuration.ReadFromFile(config_file);
+    if (!status)
+    {
+        std::cerr << "Error in configuration file: " << config_file
+                  << std::endl;
+        return false;
+    }
+
+    // setup input
+    int num_frames = 1;
+    VideoCapture cap;
+    std::string image_file;
+    if (input_file == "camera")
+    {
+        cap = VideoCapture(1);  // cap = VideoCapture("test.mp4");
+        if (! cap.isOpened())
+        {
+            std::cerr << "Cannot open camera input." << std::endl;
+            return false;
+        }
+        num_frames = NUM_VIDEO_FRAMES;
+        namedWindow("ImageNet", WINDOW_AUTOSIZE | CV_GUI_NORMAL);
+    }
+    else
+    {
+        image_file = input_file;
+    }
+
+    // Determine input frame size from configuration
+    size_t frame_sz = configuration.inWidth * configuration.inHeight *
+                      configuration.inNumChannels;
+
+    try
+    {
+        // Create a executor with the approriate core type, number of cores
+        // and configuration specified
+        Executor executor(device_type, ids, configuration);
+
+        // Query Executor for set of ExecutionObjects created
+        const ExecutionObjects& execution_objects =
+                                                executor.GetExecutionObjects();
+        int num_eos = execution_objects.size();
+
+        // Allocate input and output buffers for each execution object
+        std::vector<void *> buffers;
+        for (auto &eo : execution_objects)
+        {
+            ArgInfo in  = { ArgInfo(malloc_ddr<char>(frame_sz), frame_sz)};
+            ArgInfo out = { ArgInfo(malloc_ddr<char>(frame_sz), frame_sz)};
+            eo->SetInputOutputBuffer(in, out);
+
+            buffers.push_back(in.ptr());
+            buffers.push_back(out.ptr());
+        }
+
+        #define MAX_NUM_EOS  4
+        struct timespec t0[MAX_NUM_EOS], t1;
+
+        // Process frames with available execution objects in a pipelined manner
+        // additional num_eos iterations to flush the pipeline (epilogue)
+        for (int frame_idx = 0;
+             frame_idx < num_frames + num_eos; frame_idx++)
+        {
+            ExecutionObject* eo = execution_objects[frame_idx % num_eos].get();
+
+            // Wait for previous frame on the same eo to finish processing
+            if (eo->ProcessFrameWait())
+            {
+                clock_gettime(CLOCK_MONOTONIC, &t1);
+                double elapsed_host =
+                                ms_diff(t0[eo->GetFrameIndex() % num_eos], t1);
+                double elapsed_device = eo->GetProcessTimeInMilliSeconds();
+                double overhead = 100 - (elapsed_device/elapsed_host*100);
+
+                std::cout << "frame[" << eo->GetFrameIndex() << "]: "
+                          << "Time on device: "
+                          << std::setw(6) << std::setprecision(4)
+                          << elapsed_device << "ms, "
+                          << "host: "
+                          << std::setw(6) << std::setprecision(4)
+                          << elapsed_host << "ms ";
+                std::cout << "API overhead: "
+                          << std::setw(6) << std::setprecision(3)
+                          << overhead << " %" << std::endl;
+
+                WriteFrameOutput(*eo);
+            }
+
+            // Read a frame and start processing it with current eo
+            if (ReadFrame(*eo, frame_idx, configuration, num_frames,
+                          image_file, cap))
+            {
+                clock_gettime(CLOCK_MONOTONIC, &t0[frame_idx % num_eos]);
+                eo->ProcessFrameStartAsync();
+            }
+        }
+
+        for (auto b : buffers)
+            __free_ddr(b);
+
+    }
+    catch (tinn::Exception &e)
+    {
+        std::cerr << e.what() << std::endl;
+        status = false;
+    }
+
+    return status;
+}
+
+
+bool ReadFrame(ExecutionObject &eo, int frame_idx,
+               const Configuration& configuration, int num_frames,
+               std::string& image_file, VideoCapture &cap)
+{
+    if (frame_idx >= num_frames)
+        return false;
+    eo.SetFrameIndex(frame_idx);
+
+    char*  frame_buffer = eo.GetInputBufferPtr();
+    assert (frame_buffer != nullptr);
+
+    Mat image;
+    if (! image_file.empty())
+    {
+        image = cv::imread(image_file, CV_LOAD_IMAGE_COLOR);
+        if (image.empty())
+        {
+            std::cerr << "Unable to read from: " << image_file << std::endl;
+            return false;
+        }
+    }
+    else
+    {
+        Mat v_image;
+        if (! cap.grab())  return false;
+        if (! cap.retrieve(v_image)) return false;
+        // Crop 640x480 camera input to center 256x256 input
+        image = Mat(v_image, Rect(192, 112, 256, 256));
+        cv::imshow("ImageNet", image);
+        waitKey(2);
+    }
+
+    // TI DL image preprocessing, into frame_buffer
+    return PreProcImage(image, frame_buffer, 1, 3,
+                        configuration.inWidth, configuration.inHeight,
+                        configuration.inWidth,
+                        configuration.inWidth * configuration.inHeight,
+                        1, configuration.preProcType);
+}
+
+// Display top 5 classified imagenet classes with probabilities
+bool WriteFrameOutput(const ExecutionObject &eo)
+{
+    const int k = 5;
+    unsigned char *out = (unsigned char *) eo.GetOutputBufferPtr();
+    int out_size = eo.GetOutputBufferSizeInBytes();
+
+    // sort and get k largest values and corresponding indices
+    typedef std::pair<unsigned char, int> val_index;
+    auto constexpr cmp = [](val_index &left, val_index &right)
+                         { return left.first > right.first; };
+    std::priority_queue<val_index, std::vector<val_index>, 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
+    std::vector<val_index> sorted;
+    while (! queue.empty())
+    {
+      sorted.push_back(queue.top());
+      queue.pop();
+    }
+
+    for (int i = k - 1; i >= 0; i--)
+    {
+        std::cout << k-i << ": " << imagenet_classes[sorted[i].second]
+                  << ", prob = " << (float) sorted[i].first / 256 << std::endl;
+    }
+
+    return true;
+}
+
+
+void ProcessArgs(int argc, char *argv[], std::string& config,
+                 int& num_devices, DeviceType& device_type,
+                 std::string& input_file)
+{
+    const struct option long_options[] =
+    {
+        {"config",      required_argument, 0, 'c'},
+        {"num_devices", required_argument, 0, 'n'},
+        {"device_type", required_argument, 0, 't'},
+        {"image_file",  required_argument, 0, 'i'},
+        {"help",        no_argument,       0, 'h'},
+        {"verbose",     no_argument,       0, 'v'},
+        {0, 0, 0, 0}
+    };
+
+    int option_index = 0;
+
+    while (true)
+    {
+        int c = getopt_long(argc, argv, "c:n:t:i:hv", long_options, &option_index);
+
+        if (c == -1)
+            break;
+
+        switch (c)
+        {
+            case 'c': config = optarg;
+                      break;
+
+            case 'n': num_devices = atoi(optarg);
+                      assert (num_devices > 0 && num_devices <= 4);
+                      break;
+
+            case 't': if (*optarg == 'e')
+                          device_type = DeviceType::DLA;
+                      else if (*optarg == 'd')
+                          device_type = DeviceType::DSP;
+                      else
+                      {
+                          std::cerr << "Invalid argument to -t, only e or d"
+                                       " allowed" << std::endl;
+                          exit(EXIT_FAILURE);
+                      }
+                      break;
+
+            case 'i': input_file = optarg;
+                      break;
+
+            case 'v': __TI_show_debug_ = true;
+                      break;
+
+            case 'h': DisplayHelp();
+                      exit(EXIT_SUCCESS);
+                      break;
+
+            case '?': // Error in getopt_long
+                      exit(EXIT_FAILURE);
+                      break;
+
+            default:
+                      std::cerr << "Unsupported option: " << c << std::endl;
+                      break;
+        }
+    }
+}
+
+void DisplayHelp()
+{
+    std::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 <config>          Valid configs: j11_bn, j11_prelu, j11_v2\n"
+                 " -n <number of cores> Number of cores to use (1 - 4)\n"
+                 " -t <d|e>             Type of core. d -> DSP, e -> DLA\n"
+                 " -i <image>           Path to the image file\n"
+                 " -i camera            Use camera as input\n"
+                 " -v                   Verbose output during execution\n"
+                 " -h                   Help\n";
+}
+
diff --git a/examples/make.common b/examples/make.common
new file mode 100644 (file)
index 0000000..891b86e
--- /dev/null
@@ -0,0 +1,40 @@
+RM = rm
+AR = ar
+CP = cp
+
+TINN_DIR = ../../tinn_api
+TINN_LIB_NAME = tinn_api.a
+TINN_LIB = $(TINN_DIR)/$(TINN_LIB_NAME)
+TINN_LIB_IMGUTIL_NAME = tinn_imgutil.a
+TINN_LIB_IMGUTIL = $(TINN_DIR)/$(TINN_LIB_IMGUTIL_NAME)
+
+include $(TINN_DIR)/make.inc
+
+ifeq ($(BUILD), debug)
+       CXXFLAGS += -Og -g -ggdb
+else
+       CXXFLAGS += -O3
+endif
+
+CXXFLAGS += -I. -I$(TINN_DIR)/inc -std=c++11
+
+HEADERS = 
+LIBS    = -lOpenCL -locl_util -lpthread
+
+all: $(EXE)
+
+.PHONY: $(TINN_LIB)
+$(TINN_LIB):
+       $(MAKE) -C $(TINN_DIR) $(TINN_LIB_NAME)
+
+.PHONY: $(TINN_LIB_IMGUTIL)
+$(TINN_LIB_IMGUTIL):
+       $(MAKE) -C $(TINN_DIR) $(TINN_LIB_IMGUTIL_NAME)
+
+realclean: clean
+       $(MAKE) -C $(TINN_DIR) clean
+       $(MAKE) -C $(TINN_DIR)/dsp clean
+
+clean::
+       $(RM) -f $(EXE) stats_tool_out.* *.out
+
index a1c5b5a469e9b66188c9e610971375509e9e7bc1..49f4f411a8d4c4cd36ff633ab7ef59628c723b39 100644 (file)
@@ -1,45 +1,9 @@
 EXE = test_tinn
 
-RM = rm
-AR = ar
-CP = cp
-
-TINN_DIR = ../../tinn_api
-TINN_LIB_NAME = tinn_api.a
-TINN_LIB = $(TINN_DIR)/$(TINN_LIB_NAME)
-
-DSP_OUTFILE = $(TINN_DIR)/dsp/ocl_wrapper.out
-
-include $(TINN_DIR)/make.inc
-
-ifeq ($(BUILD), debug)
-       CXXFLAGS += -Og -g -ggdb
-else
-       CXXFLAGS += -O3
-endif
-
-CXXFLAGS += -I. -I$(TINN_DIR)/inc -std=c++11
-
-HEADERS = 
-LIBS    = -lOpenCL -locl_util -lpthread
+include ../make.common
 
 $(EXE): SOURCES = main.cpp multiple_executors.cpp
 
-$(EXE): $(TINN_LIB) $(HEADERS) $(DSP_OUTFILE) $(SOURCES)
+$(EXE): $(TINN_LIB) $(HEADERS) $(SOURCES)
        $(CXX) $(CXXFLAGS) $(SOURCES) $(TINN_LIB) $(LDFLAGS) $(LIBS) -o $@
 
-.PHONY: $(DSP_OUTFILE)
-$(DSP_OUTFILE):
-       $(MAKE) -C $(TINN_DIR)/dsp
-       $(CP) $(DSP_OUTFILE) .
-
-.PHONY: $(TINN_LIB)
-$(TINN_LIB):
-       $(MAKE) -C $(TINN_DIR) $(TINN_LIB_NAME)
-
-realclean: clean
-       $(MAKE) -C $(TINN_DIR) clean
-       $(MAKE) -C $(TINN_DIR)/dsp clean
-
-clean::
-       $(RM) -f $(EXE) stats_tool_out.* *.out
index b220fd6f64a4f4187eaff2fbfc33a862dda28795..047b29dbaef7686b9200899fe8eac4725e0c7c0f 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 1
+preProcType = 0
 inData   = testvecs/input/000100_1024x512_bgr.y
 outData   = "./stats_tool_out.bin"
 netBinFile     = testvecs/config/tidl_models/tidl_net_dense_1x1.bin
index 62a2026c4736e27e1cd9b1e6ca9e92b27c8bce8a..f8d83d0270dd185f501c5c27bf746f4f1f418bf3 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 1
+preProcType = 2
 inData   = testvecs/input/preproc_2_224x224.y
 outData   = "stats_tool_out.bin"
 netBinFile      = testvecs/config/tidl_models/tidl_inception_v1_net.bin
index 606484a114a91daab7c730f1fafd571c62e057fe..cc5be28ba66aed0493dfa9d85aaab99dbcb8b282 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 1
+preProcType = 0
 inData   = testvecs/input/preproc_0_224x224.y
 outData   = "./stats_tool_out.bin"
 netBinFile      = "testvecs/config/tidl_models/tidl_net_imagenet_jacintonet11v2_bn.bin"
index c3096e19bffa76539c9dfff5ad8e360ac3fc40bd..9ccf128c472fe61325b275b703912429d0b6337c 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames     = 1
+preProcType   = 0
 inData        = testvecs/input/preproc_3_32x32.y
 outData       = "./stats_tool_out.bin"
 netBinFile    = "testvecs/config/tidl_models/tidl_net_cifar_jacintonet11v2.bin"
index 42a2659100b727be1d7ea729ce8a21a172ee3b1f..01e68566334bdd19867ce2ea0983eb23aad065a1 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames      = 1
+preProcType    = 0
 inData         = testvecs/input/preproc_3_32x32.y
 outData        = "stats_tool_out.bin"
 netBinFile     = "testvecs/config/tidl_models/tidl_net_jacintonet_cntrllayers.bin"
index d9d4555440f9d66d59be633a5de326f30ba429f6..4ed1bf8e1ab49ebcc6bf67829956bbc4d6777570 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames       = 1
+preProcType     = 0
 inData          = testvecs/input/preproc_0_224x224.y
 outData         = "stats_tool_out.bin"
 netBinFile      = "testvecs/config/tidl_models/tidl_net_imagenet_jacintonet11v2_prelu.bin"
index 4ec4a66aaff9f63d2fc5154315b1c33d14ef9c39..1b5ea79818075e98b251fe8ebfa3d47b0f8b36c4 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 1
+preProcType = 0
 inData   = testvecs/input/preproc_0_224x224.y
 outData   = "stats_tool_out.bin"
 netBinFile      = "testvecs/config/tidl_models/tidl_net_imagenet_jacintonet11v2.bin"
index c8c756728e10b14f6eac62cb5304a6d859d44bd4..69e8071e15def6c537e3b9996649ba8381c67efe 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 1
+preProcType = 0
 inData   = testvecs/input/000100_1024x512_bgr.y
 outData   = "./stats_tool_out.bin"
 netBinFile     = testvecs/config/tidl_models/tidl_net_jsegnet21v2.bin
index 4046224359460e74d99b1131e09d17ca1b6b1103..cce0cdfda19da9dfa2535e9d87d0306abc0b5ac4 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 9
+preProcType = 0
 inData   = ./testvecs/input/000100_1024x512_bgr.y
 outData   = "./stats_tool_out.bin"
 netBinFile     = ./testvecs/config/tidl_models/jsegnet21/tidl_net_jsegnet21v2.bin
index fd1477d053118a4f4a31c97781d50eea25ff33df..925ea2731a273e622383c86df306bb1c5b46d097 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 1
+preProcType = 2
 inData   = testvecs/input/preproc_2_224x224.y
 outData   = "./stats_tool_out.bin"
 netBinFile      = "testvecs/config/tidl_models/tidl_net_mobilenet_1_224.bin"
index 64b7252501a7667b37e63e778fb67dc24e96b1b8..15ceca1b616224e46789ee41559932e58f1e267a 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 1
+preProcType = 0
 inData   = testvecs/input/000100_1024x512_bgr.y
 outData   = "./stats_tool_out.bin"
 netBinFile      = "testvecs/config/tidl_models/tidl_net_dense_varibale_block_size.bin"
index bbc12bee9901fef46e058b1b93abdc504ea6689e..56173e47d7ed57a4bc018b01b2b6c6b87dfed89b 100755 (executable)
@@ -1,4 +1,5 @@
 numFrames   = 1
+preProcType = 1
 inData   = testvecs/input/preproc_1_227x227.y
 outData   = "./stats_tool_out.bin"
 netBinFile      = "testvecs/config/tidl_models/tidl_net_squeezeNet1.1.bin"
diff --git a/examples/test/testvecs/input/airshow.jpg b/examples/test/testvecs/input/airshow.jpg
new file mode 100644 (file)
index 0000000..2214a32
Binary files /dev/null and b/examples/test/testvecs/input/airshow.jpg differ
index 82e4871d184d378f78e647c98d745be70b079e01..11008b0328824850f9c23b67b83972e42c49e52d 100644 (file)
@@ -33,9 +33,11 @@ BUILD_SHA?=$(shell git rev-parse --short HEAD)
 endif
 
 LIB_NAME = tinn_api.a
-DSP_OUTFILE = dsp/ocl_wrapper.out
+DSP_SRCFILE = dsp/ocl_wrapper.cl
+DSP_OUTFILE = dsp/ocl_wrapper.dsp_h
+LIB_IMGUTIL_NAME = tinn_imgutil.a
 
-all: $(LIB_NAME) $(DSP_OUTFILE)
+all: $(LIB_NAME) $(DSP_OUTFILE) $(LIB_IMGUTIL_NAME)
 
 include make.inc
 RM = rm
@@ -44,14 +46,19 @@ AR = ar
 
 SRCS = ocl_device.cpp configuration_parser.cpp configuration.cpp\
           executor.cpp execution_object.cpp trace.cpp util.cpp
+SRCS_IMGUTIL = imgutil.cpp
 
 OBJS = $(SRCS:.cpp=.o)
+OBJS_IMGUTIL = $(SRCS_IMGUTIL:.cpp=.o)
 
 HOST_SRC_FILES = $(addprefix src/,$(SRCS))
 HOST_OBJ_FILES = $(addprefix obj/,$(OBJS))
+HOST_SRC_IMGUTIL_FILES = $(addprefix src/,$(SRCS_IMGUTIL))
+HOST_OBJ_IMGUTIL_FILES = $(addprefix obj/,$(OBJS_IMGUTIL))
 
 HEADERS = src/ocl_device.h src/trace.h src/common_defines.h src/util.h
 HEADERS += src/executor_impl.h inc/executor.h inc/configuration.h
+HEADERS += ${DSP_OUTFILE}
 
 .PHONY: $(BUILD_ID)
 BUILD_ID := -D_BUILD_VER=$(shell echo "" | \
@@ -72,19 +79,27 @@ CXXFLAGS += -I$(TARGET_ROOTDIR)/usr/share/ti/opencl
 CXXFLAGS += -Isrc -Iinc
 CXXFLAGS += $(BUILD_ID)
 
+$(DSP_OUTFILE): $(DSP_SRCFILE)
+       $(MAKE) -C dsp
+
 obj/%.o: src/%.cpp $(HEADERS)
+       @mkdir -p obj
        @echo Compiling $< ...
        $(CXX) -c $(CXXFLAGS) $< -o $@
 
-obj_dir:
-       @mkdir -p obj
-
-$(LIB_NAME) : obj_dir $(HOST_OBJ_FILES)
+$(LIB_NAME): $(HOST_OBJ_FILES)
        $(AR) cr $@ $(HOST_OBJ_FILES)
 
-.PHONY: $(DSP_OUTFILE)
-$(DSP_OUTFILE):
-       $(MAKE) -C dsp
+
+$(LIB_IMGUTIL_NAME): HEADERS = inc/imgutil.h
+$(LIB_IMGUTIL_NAME): CXXFLAGS += $(shell pkg-config --cflags opencv)
+
+$(LIB_IMGUTIL_NAME): $(HOST_OBJ_IMGUTIL_FILES)
+       $(AR) cr $@ $(HOST_OBJ_IMGUTIL_FILES)
 
 clean::
-       $(RM) -f $(LIB_NAME) $(HOST_OBJ_FILES) $(DSP_OUTFILE)
+       $(MAKE) -C dsp clean
+       $(RM) -f $(LIB_NAME) $(HOST_OBJ_FILES)
+       $(RM) -f $(LIB_IMGUTIL_NAME) $(HOST_OBJ_IMGUTIL_FILES)
+       $(RM) -rf obj
+
index b7a81b4483a203014b62a5c18bd905537d63e3e0..e88ecdbb93bd956378d3b7223eadc696d1ca5bff 100644 (file)
@@ -1,14 +1,14 @@
 
-all: ocl_wrapper.out
+all: ocl_wrapper.dsp_h
 
 include ../make.inc
 
-CLOCL_FLAGS = -I../
+CLOCL_FLAGS = -I../ -t
 
 
-ocl_wrapper.out: ocl_wrapper.cl
+ocl_wrapper.dsp_h: ocl_wrapper.cl
        @echo Generating $@
        @$(CLOCL) $(CLOCL_FLAGS) $^
 
 clean::
-       @$(RM) *.obj *.out
+       @$(RM) *.obj *.out *.dsp_h
index 52c8fcf09c616505bcc03707c37e2b8ff396aa8e..4116829d37f32a5b39f1c241d8b8ac1344cbabc0 100644 (file)
@@ -55,6 +55,10 @@ class Configuration
     int     inNumChannels;
     int     noZeroCoeffsPercentage;
 
+     //! Pre-processing type applied to the input frame
+     //! Specific to each network, can take values from 0 to 4, default is 0
+     int    preProcType;
+
     //! Size of the TI DL per Execution Object heap
     size_t EXTMEM_HEAP_SIZE;
 
@@ -79,6 +83,7 @@ class Configuration
     Configuration(): numFrames(0), inHeight(0), inWidth(0),
                      inNumChannels(0),
                      noZeroCoeffsPercentage(100),
+                     preProcType(0),
                      EXTMEM_HEAP_SIZE(64 << 20),  // 64MB for inceptionNetv1
                      PARAM_HEAP_SIZE(9 << 20)     // 9MB for mobileNet1
     {}
diff --git a/tinn_api/inc/imgutil.h b/tinn_api/inc/imgutil.h
new file mode 100644 (file)
index 0000000..76648f8
--- /dev/null
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * 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.
+ *****************************************************************************/
+
+//! @file imgutil.h
+
+#pragma once
+#include "opencv2/core.hpp"
+#include "opencv2/imgproc.hpp"
+using namespace cv;
+
+namespace tinn {
+namespace imgutil {
+
+//! PreProcImage - preprocess image data into the value ranges that
+//! the DL network expects
+//! @param image        Input image data (OpenCV data structure)
+//! @param ptr          Output buffer that TI DL takes as input
+//! @param roi          Number of Region-Of-Interests
+//! @param n            Number of channels
+//! @param width        Input image width
+//! @param height       Input image height
+//! @param pitch        Output buffer (ptr) pitch for each line
+//! @param chOffset     Output buffer (ptr) offset for each channel
+//! @param frameCount   Number of frames in input image data
+//! @param preProcType  Preprocessing type, specified in network config
+bool PreProcImage(Mat& image, char *ptr, int16_t roi, int16_t n,
+                  int16_t width, int16_t height, int16_t pitch,
+                  int32_t chOffset, int32_t frameCount, int32_t preProcType);
+
+} // namesapce tinn::imgutil
+} // namespace tinn
index 698d5c6eff591562ab1d8b94e216d193af14141e..32635c08415d4e21bc5399e59b9d726537b778b5 100644 (file)
@@ -246,14 +246,6 @@ LIBS  = -lOpenCL -locl_util
        @echo Compiling $<
        $(CL6X) -c $(CL6XFLAGS) $<
 
-%.out: %.cl
-       @echo Compiling $<
-       $(CLOCL) $(CLOCLFLAGS) $^
-
-%.dsp_h: %.cl
-       @echo Compiling $<
-       $(CLOCL) -t $(CLOCLFLAGS) $^
-
 $(EXE):
 
 clean::
index 7c6975cac98b3d4b2bc7989de4df17a057b45edf..74ec552a0894a37684963794c78a99b00726ecab 100644 (file)
@@ -38,6 +38,7 @@ void Configuration::Print(std::ostream &os) const
     os << "Configuration"
        << "\nFrame=      " << numFrames << " " << inWidth << "x"
                            << inHeight << "x" << inNumChannels
+       << "\nPreProcType              " << preProcType
        << "\nInputFile                " << inData
        << "\nOutputFile               " << outData
        << "\nNetwork                  " << netBinFile
index 271ec199d77f72d95f6d9d2a1fdc753d5b0789d5..e246f4d0bfcafaee9696445d14a925bec8222b13 100644 (file)
@@ -60,6 +60,7 @@ struct ConfigParser : qi::grammar<Iterator, ascii::space_type>
 
         entry %=
           lit("numFrames")   >> '=' >> int_[ph::ref(x.numFrames) = _1]    |
+          lit("preProcType") >> '=' >> int_[ph::ref(x.preProcType) = _1]    |
           lit("inWidth")     >> '=' >> int_[ph::ref(x.inWidth) = _1]   |
           lit("inHeight")    >> '=' >> int_[ph::ref(x.inHeight) = _1]  |
           lit("inNumChannels") >> '=' >> int_[ph::ref(x.inNumChannels) = _1]  |
index 8236a33b48e47f149949391bb8e2979a2e767ec0..6ca2d63f94e5fda6faff874cd1aa3dc186e6710e 100644 (file)
@@ -53,7 +53,7 @@ ExecutorImpl::ExecutorImpl(DeviceType core_type, const DeviceIds& ids):
 {
     std::string name;
     if (core_type_m == DeviceType::DSP)
-        name  = "ocl_wrapper.out";
+        name  = "";
     else if (core_type_m == DeviceType::DLA)
         name = STRING(SETUP_KERNEL) ";" STRING(INIT_KERNEL) ";" STRING(PROCESS_KERNEL) ";" STRING(CLEANUP_KERNEL);
 
diff --git a/tinn_api/src/imgutil.cpp b/tinn_api/src/imgutil.cpp
new file mode 100644 (file)
index 0000000..668080c
--- /dev/null
@@ -0,0 +1,222 @@
+/******************************************************************************
+ * 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 <iostream>
+#include "imgutil.h"
+
+using namespace tinn;
+
+bool tinn::imgutil::PreProcImage(
+                  Mat& image, char *ptr, int16_t roi, int16_t n,
+                  int16_t width, int16_t height, int16_t pitch,
+                  int32_t chOffset, int32_t frameCount, int32_t preProcType)
+{
+  int32_t  i0, i1, i2, i3;
+  Mat spl[3];
+  int32_t enableMeanSub = 0;
+  Mat tempImage;
+  int32_t meanVlaues[3];
+
+  if(preProcType == 0) // Caffe-Jacinto Models
+  {
+   int32_t crop_width    =  width;
+   int32_t crop_height    =  height;
+   int32_t half_the_width  =  256/ 2;
+   int32_t half_the_height =  256/ 2;
+
+   int32_t startX  = half_the_width -crop_width/2;
+   int32_t startY  = half_the_height -crop_height/2;
+
+   cv::Rect myROI(startX,
+   startY,
+   crop_width,
+   crop_height);
+   cv::resize(image, tempImage, Size(256,256), 0,0,cv::INTER_AREA);
+   image = tempImage(myROI);
+   enableMeanSub = 0;
+  }
+  else if (preProcType == 1) // Caffe Models , eg : SqueezeNet
+  {
+
+   int32_t crop_width    =  width;
+   int32_t crop_height    =  height;
+   int32_t half_the_width  =  256/ 2;
+   int32_t half_the_height =  256/ 2;
+
+   int32_t startX  = half_the_width -crop_width/2;
+   int32_t startY  = half_the_height -crop_height/2;
+
+   cv::Rect myROI(startX,
+   startY,
+   crop_width,
+   crop_height);
+   cv::resize(image, tempImage, Size(256,256), 0,0,cv::INTER_AREA);
+   image = tempImage(myROI);
+   enableMeanSub = 1;
+   meanVlaues[0] = 104;
+   meanVlaues[1] = 117;
+   meanVlaues[2] = 123;
+
+  }
+  else if (preProcType == 2)
+  {
+   cv::cvtColor(image, image, CV_BGR2RGB);
+   float factor  = 0.875;
+   int32_t orgWidth  = image.size[1];
+   int32_t orgHeight = image.size[0];
+
+   int32_t crop_width    =  orgWidth*factor;
+   int32_t crop_height    =  orgHeight*factor;
+   int32_t half_the_width  = orgWidth/ 2;
+   int32_t half_the_height = orgHeight / 2;
+
+   int32_t startX  = half_the_width -crop_width/2;
+   int32_t startY  = half_the_height -crop_height/2;
+
+   cv::Rect myROI(startX,
+   startY,
+   crop_width,
+   crop_height);
+   tempImage = image(myROI);
+   cv::resize(tempImage, image, Size(width,height), 0,0,CV_INTER_AREA);
+   enableMeanSub = 1;
+   meanVlaues[0] = 128;
+   meanVlaues[1] = 128;
+   meanVlaues[2] = 128;
+  }
+  else if (preProcType == 3)
+  {
+   cv::cvtColor(image, image, CV_BGR2RGB);
+   int32_t crop_width    =  width;
+   int32_t crop_height    =  height;
+   int32_t half_the_width  =  32/ 2;
+   int32_t half_the_height =  32/ 2;
+
+   int32_t startX  = half_the_width -crop_width/2;
+   int32_t startY  = half_the_height -crop_height/2;
+
+   cv::Rect myROI(startX,
+   startY,
+   crop_width,
+   crop_height);
+   cv::resize(image, tempImage, Size(32,32), 0,0,cv::INTER_AREA);
+   image = tempImage(myROI);
+   enableMeanSub = 0;
+  }
+  else if (preProcType == 4)
+  {
+   //cv::cvtColor(image, image, CV_BGR2RGB);
+   int32_t crop_width    =  width;
+   int32_t crop_height    =  height;
+   int32_t half_the_width  =  width/ 2;
+   int32_t half_the_height =  height/ 2;
+
+   int32_t startX  = half_the_width -crop_width/2;
+   int32_t startY  = half_the_height -crop_height/2;
+
+   cv::Rect myROI(startX,
+   startY,
+   crop_width,
+   crop_height);
+   cv::resize(image, tempImage, Size(width,height), 0,0,cv::INTER_AREA);
+   image = tempImage(myROI);
+   enableMeanSub = 0;
+  }
+  else
+  {
+    std::cerr << "Unsupported preProcType : " << preProcType << std::endl;
+    return false;
+  }
+
+  if(image.channels() > 3)
+  {
+   return false;
+  }
+  if(image.total() != (unsigned int) (height * width))
+  {
+   return false;
+  }
+  int size = (int)image.total()*image.channels();
+  uint8_t * data = (uint8_t*)malloc(size);
+
+  if(data == NULL)
+  {
+   return false;
+  }
+
+  split(image,spl);
+  for(i0 = 0; i0 < image.channels(); i0++)
+  {
+   std::memcpy(&data[i0*((int)image.total())],spl[i0].data,((int)image.total()) * sizeof(uint8_t));
+  }
+  for(i2 = 0; i2 < roi; i2++)
+  {
+   for(i0 = 0; i0 < n; i0++)
+   {
+    for(i1 = 0; i1 < height; i1++)
+    {
+      for(i3 = 0; i3 < width; i3++)
+      {
+       int32_t in;
+
+       if(enableMeanSub)
+       {
+        if(n != 1)
+        {
+          in =  data[i2*n*width*height + i0*width*height+ i1*width + i3] - meanVlaues[i0];
+        }
+        else
+        {
+          in =  data[i2*1*width*height + i1*width + i3] - meanVlaues[i0];
+        }
+
+        if(in > 127)  in  = 127;
+        if(in < -128) in = -128;
+       }
+       else
+       {
+
+        if(n != 1)
+        {
+          in =  data[i2*n*width*height + i0*width*height+ i1*width + i3];
+        }
+        else
+        {
+          in =  data[i2*1*width*height + i1*width + i3];
+        }
+       }
+
+       ptr[i2*n*chOffset + i0*chOffset + i1*pitch + i3] = in;
+      }
+    }
+   }
+  }
+
+  std::free(data);
+  return true;
+}
index e98a00ab9625e097c363a54c671a364c9245555a..d8aff36299cea067f3151d922e6c5820436a50c9 100644 (file)
@@ -36,6 +36,7 @@ using std::size_t;
 #include "ocl_device.h"
 #include "ocl_util.h"
 #include "trace.h"
+#include "../dsp/ocl_wrapper.dsp_h"
 
 using namespace tinn;
 
@@ -206,13 +207,13 @@ bool DspDevice::BuildProgramFromBinary(const std::string &BFN,
                                        cl_device_id device_ids[],
                                        int num_devices)
 {
-    char *bin_arr;
-    size_t bin_len = ocl_read_binary(BFN.c_str(), bin_arr);
+    size_t bin_len = ocl_wrapper_dsp_bin_len;
 
     assert (bin_len != 0);
 
     // Casting to make ocl_read_binary work with clCreateProgramWithBinary
-    const unsigned char *bin_arrc = reinterpret_cast <const unsigned char *>(bin_arr);
+    const unsigned char *bin_arrc = reinterpret_cast <const unsigned char *>
+                                    (ocl_wrapper_dsp_bin);
 
     size_t lengths[num_devices];
     for (int i=0; i < num_devices; i++) lengths[i] = bin_len;
@@ -234,8 +235,6 @@ bool DspDevice::BuildProgramFromBinary(const std::string &BFN,
     err = clBuildProgram(program_m, num_devices, device_ids, options, 0, 0);
     errorCheck(err, __LINE__);
 
-    delete bin_arr;
-
     return true;
 }