Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating Handwritten Digits on MNIST using GANs #161

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,353 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.Add(new mlpack::ann::Convolution<>(,6,5,5,1,1,0,0,28,28))

Could you try this?


Reply via ReviewNB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but it doesn't seems to work too.
input_line_65:2:16: error: no matching constructor for initialization of 'mlpack::ann::Convolution<>' model.Add(new mlpack::ann::Convolution<>(1,6,5,5,1,1,0,0,28,28)); ^ ~~~~~~~~~~~~~~~~~~~~~ /home/viole/anaconda3/envs/notebook/include/mlpack/methods/ann/layer/layer_types.hpp:172:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 10 were provided class Convolution; ^ /home/viole/anaconda3/envs/notebook/include/mlpack/methods/ann/layer/layer_types.hpp:172:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 10 were provided

No matching constructor..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it on lab.mlpack.org and there it works fine, I had some problems with namespaces in the past, can you put each namespace into a separate cell?

"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c23013fc",
"metadata": {},
"outputs": [],
"source": [
"#include<mlpack/xeus-cling.hpp>\n",
"#include<mlpack/core.hpp>\n",
"#include<mlpack/core/data/split_data.hpp>\n",
"#include<mlpack/methods/ann/layer/layer.hpp>\n",
"#include<mlpack/methods/ann/ffn.hpp>\n",
"#include<bits/stdc++.h>\n",
"#include<ensmallen.hpp>"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ad7ab4c6",
"metadata": {},
"outputs": [],
"source": [
"using namespace mlpack;\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0c8af9e2",
"metadata": {},
"outputs": [],
"source": [
"using namespace mlpack::ann;"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ff1b2e2f",
"metadata": {},
"outputs": [],
"source": [
"using namespace arma;"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "4834841f",
"metadata": {},
"outputs": [],
"source": [
"using namespace std;"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "d1dc9cb6",
"metadata": {},
"outputs": [],
"source": [
"using namespace ens;"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7ed7a903",
"metadata": {},
"outputs": [],
"source": [
"arma::Row<size_t> getLabels(arma::mat predOut){\n",
" arma::Row<size_t> predLabels(predOut.n_cols);\n",
" for( arma::uword i = 0; i < predOut.n_cols; ++i){\n",
" predLabels(i) = predOut.col(i).index_max();\n",
" }\n",
" return predLabels;\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "131fe748",
"metadata": {},
"outputs": [],
"source": [
"constexpr double RATIO = 0.1;\n",
"constexpr int MAX_ITERATIONS = 0;\n",
"constexpr double STEP_SIZE = 1.2e-3;\n",
"constexpr int BATCH_SIZE = 50;"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "697a8d63",
"metadata": {},
"outputs": [],
"source": [
"arma::mat dataset;"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "64ee4e72",
"metadata": {},
"outputs": [],
"source": [
"data::Load(\"/home/viole/swaingotnochill/examples/generating_hand_written_digits_mnist_with_gan/digit-recognizer/train.csv\", dataset, true);"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "d8a3d8da",
"metadata": {},
"outputs": [],
"source": [
"arma::mat train, valid;"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "da10fdac",
"metadata": {},
"outputs": [],
"source": [
"data::Split(dataset, train, valid, RATIO);"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "a6a484e7",
"metadata": {},
"outputs": [],
"source": [
"const arma::mat trainX = train.submat(1, 0, train.n_rows - 1, train.n_cols - 1);\n",
"const arma::mat validX = valid.submat(1, 0, valid.n_rows - 1, valid.n_cols - 1);"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "db267de6",
"metadata": {},
"outputs": [],
"source": [
"const arma::mat trainY = train.row(0);\n",
"const arma::mat validY = valid.row(0);"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "7eb2907b",
"metadata": {},
"outputs": [],
"source": [
"FFN<NegativeLogLikelihood<>, RandomInitialization> model;"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "ffc66454",
"metadata": {},
"outputs": [],
"source": [
"model.Add<mlpack::ann::Convolution<>> (1,6,5,5,1,1,0,0,28,28);\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "03d0646a",
"metadata": {},
"outputs": [],
"source": [
"model.Add<LeakyReLU<>>();"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "2fff115e",
"metadata": {},
"outputs": [],
"source": [
"model.Add<MaxPooling<>>(2,\n",
" 2,\n",
" 2,\n",
" 2,\n",
" true);"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "462e4ce2",
"metadata": {},
"outputs": [],
"source": [
"model.Add<Convolution<>>(6,\n",
" 16,\n",
" 5,\n",
" 5,\n",
" 1,\n",
" 1,\n",
" 0,\n",
" 0,\n",
" 12,\n",
" 12);"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "73033233",
"metadata": {},
"outputs": [],
"source": [
"model.Add<LeakyReLU<>>();"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "ee5d88cc",
"metadata": {},
"outputs": [],
"source": [
"model.Add<LeakyReLU<>>();"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "7859b83e",
"metadata": {},
"outputs": [],
"source": [
"model.Add<MaxPooling<>>(2,2,2,2,true);"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "f423475d",
"metadata": {},
"outputs": [],
"source": [
"model.Add<Linear<>>(16*4*4, 10);"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "369063ba",
"metadata": {},
"outputs": [],
"source": [
"model.Add<LogSoftMax<>>();"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "17dfcdef",
"metadata": {},
"outputs": [],
"source": [
"ens::Adam optimizer(STEP_SIZE,\n",
" BATCH_SIZE,\n",
" 0.9,\n",
" 0.999,\n",
" 1e-8,\n",
" MAX_ITERATIONS,\n",
" 1e-8,\n",
" true);"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "c52947c7",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"error: Mat::operator(): index out of bounds\n"
]
},
{
"ename": "Standard Exception",
"evalue": "Mat::operator(): index out of bounds",
"output_type": "error",
"traceback": [
"Standard Exception: Mat::operator(): index out of bounds"
]
}
],
"source": [
"model.Train(trainX,\n",
" trainY,\n",
" optimizer,\n",
" ens::PrintLoss(),\n",
" ens::ProgressBar(),\n",
" ens::EarlyStopAtMinLoss(\n",
" [&](const arma::mat&){\n",
" double validationLoss = model.Evaluate(validX, validY);\n",
" std::cout << \"Validation Loss\" << validationLoss << \".\" << \"\\n\";\n",
" return validationLoss;\n",
" }))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6060587",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "C++14",
"language": "C++14",
"name": "xcpp14"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file not shown.
Loading