-
Notifications
You must be signed in to change notification settings - Fork 91
GANs mnist #172
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
Open
swaingotnochill
wants to merge
22
commits into
mlpack:master
Choose a base branch
from
swaingotnochill:gans
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
GANs mnist #172
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8ff8b75
added pycache to gitignore
swaingotnochill f0ea62c
Merge branch 'master' of https://github.com/mlpack/examples
swaingotnochill a1bf251
Training Script for GAN
swaingotnochill 3a68c83
tested training script
swaingotnochill acb2048
gan image generate and sampling
swaingotnochill 90214b6
gan genenrate csv files
swaingotnochill 3f9bafe
gans generating images
swaingotnochill 2ebecff
commented generator architecture
swaingotnochill 7ded9fc
modified mnist_gan_generate file
swaingotnochill e55e29e
add generate image cpython script
swaingotnochill 0a6a590
cleaned mnist gan file
swaingotnochill abfcd33
cleaned mnist generate file
swaingotnochill e155073
modified generateimage python script
swaingotnochill bc3afc2
changed makefile for Push
swaingotnochill e3f9003
finalized generate image for Push
swaingotnochill 8ba21fd
add samples posterior folder
swaingotnochill a9d5011
modified mnist gan notebook
swaingotnochill 2a45d92
add mnist_gan for push
swaingotnochill 2ea30b2
push
swaingotnochill 4cac2a4
add all files
swaingotnochill 25abdc9
push
swaingotnochill 3281b0a
add new line at the end of file
swaingotnochill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .ipynb_checkpoints | ||
| saved_models | ||
| samples_posterior | ||
| samples_csv_files | ||
| mnist_first250_training_4s_and_9s.arm | ||
| mnist_gan | ||
| mnist_gan_generate | ||
| mnist_gan_generate.o | ||
| mnist_gan.o | ||
| .vscode | ||
| mnist_gan.ipynb | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
|
|
||
| TARGET := mnist_gan_generate | ||
| SRC := mnist_gan_generate.cpp | ||
| LIBS_NAME := armadillo mlpack | ||
|
|
||
| CXX := g++ | ||
| CXXFLAGS += -std=c++11 -Wall -Wextra -O3 -DNDEBUG | ||
| # Use these CXXFLAGS instead if you want to compile with debugging symbols and | ||
| # without optimizations. | ||
| # CXXFLAGS += -std=c++11 -Wall -Wextra -g -O0 | ||
| LDFLAGS += -fopenmp | ||
| LDFLAGS += -lboost_serialization | ||
| LDFLAGS += -larmadillo | ||
| LDFLAGS += -L /home/viole/mlpack/build/lib/ # /path/to/mlpack/library/ # if installed locally. | ||
| # Add header directories for any includes that aren't on the | ||
| # default compiler search path. | ||
| INCLFLAGS := -I /home/viole/mlpac/build/include/ | ||
| CXXFLAGS += $(INCLFLAGS) | ||
|
|
||
| OBJS := $(SRC:.cpp=.o) | ||
| LIBS := $(addprefix -l,$(LIBS_NAME)) | ||
| CLEAN_LIST := $(TARGET) $(OBJS) | ||
|
|
||
| # default rule | ||
| default: all | ||
|
|
||
| $(TARGET): $(OBJS) | ||
| $(CXX) $(CXXFLAGS) $(OBJS) -o $(TARGET) $(LDFLAGS) $(LIBS) | ||
|
|
||
| .PHONY: all | ||
| all: $(TARGET) | ||
|
|
||
| .PHONY: clean | ||
| clean: | ||
| @echo CLEAN $(CLEAN_LIST) | ||
| @rm -f $(CLEAN_LIST) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 1, | ||
| "id": "81c68540", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from PIL import Image\n", | ||
| "import numpy as np" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 4, | ||
| "id": "25021e81", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "samples = np.genfromtxt(\"samples_csv_files/ouput_mnist_2.csv\", delimiter = ',', dtype = np.uint8)\n", | ||
| "\n", | ||
| "img = Image.fromarray(samples)\n", | ||
| "img.show()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 8, | ||
| "id": "af43503a", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import pandas as pd\n", | ||
| "dataset = pd.read_csv(\"samples_csv_files/ouput_mnist_2.csv\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 3, | ||
| "id": "47913b40", | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "ename": "FileNotFoundError", | ||
| "evalue": "[Errno 2] No such file or directory: 'samples_csv_files/output_mnist_2.csv'", | ||
| "output_type": "error", | ||
| "traceback": [ | ||
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
| "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", | ||
| "\u001b[0;32m<ipython-input-3-66cb548918f0>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"samples_csv_files/output_mnist_2.csv\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mf_in\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mline\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mf_in\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mline\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
| "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'samples_csv_files/output_mnist_2.csv'" | ||
| ] | ||
| } | ||
| ], | ||
| "source": [ | ||
| "with open(\"samples_csv_files/output_mnist_2.csv\", 'r') as f_in:\n", | ||
| " for line in f_in:\n", | ||
| " print(line)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 9, | ||
| "id": "b8584b96", | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "name": "stdout", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "<class 'pandas.core.frame.DataFrame'>\n", | ||
| "RangeIndex: 55 entries, 0 to 54\n", | ||
| "Columns: 280 entries, 9.94226905097128e-01 to 1.00000000000000e+00.264\n", | ||
| "dtypes: float64(280)\n", | ||
| "memory usage: 120.4 KB\n" | ||
| ] | ||
| } | ||
| ], | ||
| "source": [ | ||
| "dataset.info()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 15, | ||
| "id": "a68eb523", | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "name": "stdout", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "<class 'pandas.core.frame.DataFrame'>\n", | ||
| "RangeIndex: 55 entries, 0 to 54\n", | ||
| "Columns: 280 entries, 9.99801803453734e-01 to 9.96537507993331e-01\n", | ||
| "dtypes: float64(280)\n", | ||
| "memory usage: 120.4 KB\n" | ||
| ] | ||
| } | ||
| ], | ||
| "source": [ | ||
| "dataset = pd.read_csv(\"samples_csv_files/samples_posterior.csv\")\n", | ||
| " \n", | ||
| "dataset.info()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 11, | ||
| "id": "338ae5db", | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "ename": "OSError", | ||
| "evalue": "samples_csv_files/output_mnist_2.csv not found.", | ||
| "output_type": "error", | ||
| "traceback": [ | ||
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
| "\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)", | ||
| "\u001b[0;32m<ipython-input-11-28815900d631>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msamples\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenfromtxt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"samples_csv_files/output_mnist_2.csv\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdelimiter\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\",\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint8\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mimg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mImage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfromarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msamples\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mimg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
| "\u001b[0;32m~/anaconda3/envs/notebook/lib/python3.7/site-packages/numpy/lib/npyio.py\u001b[0m in \u001b[0;36mgenfromtxt\u001b[0;34m(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows, encoding, like)\u001b[0m\n\u001b[1;32m 1789\u001b[0m \u001b[0mfname\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos_fspath\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1790\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1791\u001b[0;31m \u001b[0mfid\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_datasource\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'rt'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1792\u001b[0m \u001b[0mfid_ctx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcontextlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclosing\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1793\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
| "\u001b[0;32m~/anaconda3/envs/notebook/lib/python3.7/site-packages/numpy/lib/_datasource.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(path, mode, destpath, encoding, newline)\u001b[0m\n\u001b[1;32m 192\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 193\u001b[0m \u001b[0mds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDataSource\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdestpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 194\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnewline\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnewline\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 195\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 196\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | ||
| "\u001b[0;32m~/anaconda3/envs/notebook/lib/python3.7/site-packages/numpy/lib/_datasource.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, path, mode, encoding, newline)\u001b[0m\n\u001b[1;32m 529\u001b[0m encoding=encoding, newline=newline)\n\u001b[1;32m 530\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 531\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mIOError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"%s not found.\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 532\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 533\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | ||
| "\u001b[0;31mOSError\u001b[0m: samples_csv_files/output_mnist_2.csv not found." | ||
| ] | ||
| } | ||
| ], | ||
| "source": [ | ||
| "samples = np.genfromtxt(\"samples_csv_files/output_mnist_2.csv\", delimiter=\",\", dtype = np.uint8)\n", | ||
| "img = Image.fromarray(samples)\n", | ||
| "img.show()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "57ef526f", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.7.8" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** | ||
| * @file gan_utils.cpp | ||
| * @author Roshan Swain | ||
| * @author Atharva Khandait | ||
| * | ||
| * Utility function necessary for working with GAN models. | ||
| * | ||
| * mlpack is free software; you may redistribute it and/or modify it under the | ||
| * terms of the 3-clause BSD license. You should have received a copy of the | ||
| * 3-clause BSD license along with mlpack. If not, see | ||
| * http://www.opensource.org/licenses/BSD-3-Clause for more information. | ||
| */ | ||
|
|
||
| #ifndef MODELS_GAN_UTILS_HPP | ||
| #define MODELS_GAN_UTILS_HPP | ||
|
|
||
| #include <mlpack/core.hpp> | ||
| #include <mlpack/methods/ann/ffn.hpp> | ||
|
|
||
| using namespace mlpack; | ||
| using namespace mlpack::ann; | ||
|
|
||
| // Sample from the output distribution and post-process the outputs(because | ||
| // we pre-processed it before passing it to the model). | ||
| template<typename DataType = arma::mat> | ||
| void GetSample(DataType &input, DataType& samples, bool isBinary) | ||
| { | ||
| if (isBinary) | ||
| { | ||
| samples = arma::conv_to<DataType>::from( | ||
| arma::randu<DataType>(input.n_rows, input.n_cols) <= input); | ||
| samples *= 255; | ||
| } | ||
| else | ||
| { | ||
| samples = input / 2 + 0.5; | ||
| samples *= 255; | ||
| samples = arma::clamp(samples, 0, 255); | ||
| } | ||
| } | ||
|
|
||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.