From: Jihoon Lee Date: Thu, 24 Jun 2021 08:36:45 +0000 (+0900) Subject: [Resnet/skeleton] Add helper functions X-Git-Tag: accepted/tizen/unified/20210829.234903~232 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a09b2b6f495557bfc1cf090e1bef9ca71c749b7f;p=platform%2Fcore%2Fml%2Fnntrainer.git [Resnet/skeleton] Add helper functions **Changes proposed in this PR:** - Add `withKey()`, `resnetBlock()`, `createResnet18()` **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Jihoon Lee --- diff --git a/.gitignore b/.gitignore index 5ecaa45..bf87f96 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ __pycache__/ # flatbuffer compiled header *_generated.h + +# dataset from prepare_dataset.sh +cifar-100-binary/ diff --git a/Applications/Resnet/jni/cifar_dataloader.h b/Applications/Resnet/jni/cifar_dataloader.h new file mode 100644 index 0000000..e69de29 diff --git a/Applications/Resnet/jni/main.cpp b/Applications/Resnet/jni/main.cpp index 7f46bfb..cbfc116 100644 --- a/Applications/Resnet/jni/main.cpp +++ b/Applications/Resnet/jni/main.cpp @@ -15,6 +15,70 @@ #include #include +#include + +using LayerHandle = std::shared_ptr; +using ModelHandle = std::unique_ptr; + +/** + * @brief make "key=value" from key and value + * + * @tparam T type of a value + * @param key key + * @param value value + * @return std::string with "key=value" + */ +template +static std::string withKey(const std::string &key, const T &value) { + std::stringstream ss; + ss << "key=" << value; + return ss.str(); +} + +template +static std::string withKey(const std::string &key, + const std::vector &value) { + if (value.empty()) { + throw std::invalid_argument("empty vector cannot be converted"); + } + + std::stringstream ss; + ss << "key="; + for (unsigned int i = 0; i < value.size() - 1; ++i) { + ss << value.at(i) << ','; + } + ss << value.back(); + + return ss.str(); +} + +/** + * @brief resnet block + * + * @param block_name name of the block + * @param input_name name of the input + * @param filters number of filters + * @param kernel_size number of kernel_size + * @param downsample downsample to make output size 0 + * @return std::vector vectors of layers + */ +std::vector resnetBlock(const std::string &block_name, + const std::string &input_name, int filters, + int kernel_size, bool downsample) { + return {}; +} + +/**s + * @brief Create resnet 18 + * + * @return ModelHandle to create model + */ +ModelHandle createResnet18() { + std::vector layers; + return nullptr; +} + +ml_train_datagen_cb train_cb, valid_cb; int main() { std::cout << "Hello world\n"; diff --git a/Applications/Resnet/res/prepare_dataset.sh b/Applications/Resnet/res/prepare_dataset.sh new file mode 100755 index 0000000..c156f64 --- /dev/null +++ b/Applications/Resnet/res/prepare_dataset.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e +TARGET_PATH=$1 + +if [ $# -eq 0 ]; then + echo "No argument provided, Target path = $(pwd)" + TARGET_PATH=$(pwd) +fi + +if [ ! -d "$TARGET_PATH" ]; then + echo "given arugment is not directory, aborting!" + exit 1 +fi + +dataset_path=$TARGET_PATH/cifar-100-binary +zip_path=$dataset_path.tar.gz +wget -O $zip_path https://www.cs.toronto.edu/~kriz/cifar-100-binary.tar.gz +tar -zxvf $zip_path