You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/09/24 09:42:51 UTC

[GitHub] nswamy commented on a change in pull request #12636: [MXNET-982] Provide example to illustrate usage of CSVIter in C++ API

nswamy commented on a change in pull request #12636: [MXNET-982] Provide example to illustrate usage of CSVIter in C++ API
URL: https://github.com/apache/incubator-mxnet/pull/12636#discussion_r219775911
 
 

 ##########
 File path: cpp-package/example/mlp_csv_cpu.cpp
 ##########
 @@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Amol Lele amol.github@gmail.com
+ */
+
+/*
+ * Example: mlp_csv_cpu
+ * Description:
+ * The following example demonstrates how to use CSVIter. This example creates
+ * mlp (multi-layer perceptron) model and trains the MNIST data which is in
+ * CSV format.
+ */
+#include <chrono>
+#include "utils.h"
+#include "mxnet-cpp/MxNetCpp.h"
+
+using namespace mxnet::cpp;
+
+/*
+ * Implementing the mlp symbol with given layer configuration.
+ */
+Symbol mlp(const std::vector<int> &layers)
+{
+    auto x = Symbol::Variable("X");
+    auto label = Symbol::Variable("label");
+
+    std::vector<Symbol> weights(layers.size());
+    std::vector<Symbol> biases(layers.size());
+    std::vector<Symbol> outputs(layers.size());
+
+    for (size_t i = 0; i < layers.size(); ++i) {
+        weights[i] = Symbol::Variable("w" + std::to_string(i));
+        biases[i] = Symbol::Variable("b" + std::to_string(i));
+        Symbol fc = FullyConnected(
+                                   i == 0? x : outputs[i-1],  // data
+                                   weights[i],
+                                   biases[i],
+                                   layers[i]);
+        outputs[i] = i == layers.size()-1 ? fc : Activation(fc, ActivationActType::kRelu);
+    }
+    return SoftmaxOutput(outputs.back(), label);
+}
+
+
+int main(int argc, char** argv)
+{
+    const int image_size = 28;
+    const int num_mnist_features = image_size * image_size;
+    const std::vector<int> layers{128, 64, 10};
 
 Review comment:
   layers->hidden_layer_size? layers generally is referred to convolution, pooling, dense, etc.,

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services