[Resnet/skeleton] Add helper functions
authorJihoon Lee <jhoon.it.lee@samsung.com>
Thu, 24 Jun 2021 08:36:45 +0000 (17:36 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 30 Jun 2021 04:25:49 +0000 (13:25 +0900)
**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 <jhoon.it.lee@samsung.com>
.gitignore
Applications/Resnet/jni/cifar_dataloader.h [new file with mode: 0644]
Applications/Resnet/jni/main.cpp
Applications/Resnet/res/prepare_dataset.sh [new file with mode: 0755]

index 5ecaa45..bf87f96 100644 (file)
@@ -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 (file)
index 0000000..e69de29
index 7f46bfb..cbfc116 100644 (file)
 #include <vector>
 
 #include <layer.h>
+#include <model.h>
+
+using LayerHandle = std::shared_ptr<ml::train::Layer>;
+using ModelHandle = std::unique_ptr<ml::train::Model>;
+
+/**
+ * @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 <typename T>
+static std::string withKey(const std::string &key, const T &value) {
+  std::stringstream ss;
+  ss << "key=" << value;
+  return ss.str();
+}
+
+template <typename T>
+static std::string withKey(const std::string &key,
+                           const std::vector<T> &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<LayerHandle> vectors of layers
+ */
+std::vector<LayerHandle> 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<LayerHandle> 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 (executable)
index 0000000..c156f64
--- /dev/null
@@ -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