<kaggle_start><data_title>MNIST in CSV<data_description># The MNIST dataset provided in a easy-to-use CSV format
The [original dataset](http://yann.lecun.com/exdb/mnist/) is in a format that is difficult for beginners to use. This dataset uses the work of [Joseph Redmon](https://pjreddie.com/) to provide the [MNIST dataset in a CSV format](https://pjreddie.com/projects/mnist-in-csv/).

The dataset consists of two files:

1. `mnist_train.csv`
2. `mnist_test.csv`

The `mnist_train.csv` file contains the 60,000 training examples and labels. The `mnist_test.csv` contains 10,000 test examples and labels. Each row consists of 785 values: the first value is the label (a number from 0 to 9) and the remaining 784 values are the pixel values (a number from 0 to 255).<data_name>mnist-in-csv
<code># # A conditional Conv-GAN using MXNet on the MNIST dataset
# ![image.png](attachment:image.png)
import numpy as np
import mxnet as mx
import pandas as pd
import matplotlib.pyplot as plt
import os

print(os.listdir("../input"))
# Any results you write to the current directory are saved as output.

# ## Figuring out the data format and making it usable
train_data_ = pd.read_csv("../input/mnist_train.csv")
test_data_ = pd.read_csv("../input/mnist_test.csv")
print(train_data_.head())
train_label = train_data_["label"]
test_label = test_data_["label"]
train_data = train_data_.drop(columns="label").values
test_data = test_data_.drop(columns="label").values
print(train_data.shape)


# ### Trying to recreate the images
def get_image(mat):
    mat = mat.reshape((28, 28))
    print(mat.shape)
    plt.imshow(mat, cmap="gray")
    plt.show


def get_sturctured_images(data):
    # convert to batch_size X width X height form
    data = data.reshape((-1, 28, 28))
    return data


# plot the image at this index:
idx = 4
get_image(train_data[idx])


#
# ***
# ## The Conditional Conv-GAN model
# The model specifics
ctx = mx.gpu(0)


# The Generator Module
def gen_module():
    # just create the generator module and return it
    # it would generate an image from some random number
    no_bias = True
    fix_gamma = True
    epsilon = 1e-5 + 1e-12
    rand = mx.sym.Variable("rand")
    g1 = mx.sym.Deconvolution(
        rand, name="g1", kernel=(4, 4), num_filter=1024, no_bias=no_bias
    )
    gbn1 = mx.sym.BatchNorm(g1, name="gbn1", fix_gamma=fix_gamma, eps=epsilon)
    gact1 = mx.sym.Activation(gbn1, name="gact1", act_type="relu")
    g2 = mx.sym.Deconvolution(
        gact1,
        name="g2",
        kernel=(4, 4),
        stride=(2, 2),
        pad=(1, 1),
        num_filter=512,
        no_bias=no_bias,
    )
    gbn2 = mx.sym.BatchNorm(g2, name="gbn2", fix_gamma=fix_gamma, eps=epsilon)
    gact2 = mx.sym.Activation(gbn2, name="gact2", act_type="relu")
    g3 = mx.sym.Deconvolution(
        gact2,
        name="g3",
        kernel=(4, 4),
        stride=(2, 2),
        pad=(1, 1),
        num_filter=256,
        no_bias=no_bias,
    )
    gbn3 = mx.sym.BatchNorm(g3, name="gbn3", fix_gamma=fix_gamma, eps=epsilon)
    gact3 = mx.sym.Activation(gbn3, name="gact3", act_type="relu")
    g4 = mx.sym.Deconvolution(
        gact3,
        name="g4",
        kernel=(4, 4),
        stride=(2, 2),
        pad=(1, 1),
        num_filter=128,
        no_bias=no_bias,
    )
    gbn4 = mx.sym.BatchNorm(g4, name="gbn4", fix_gamma=fix_gamma, eps=epsilon)
    gact4 = mx.sym.Activation(gbn4, name="gact4", act_type="relu")
    g5 = mx.sym.Deconvolution(
        gact4,
        name="g5",
        kernel=(4, 4),
        stride=(2, 2),
        pad=(1, 1),
        num_filter=3,
        no_bias=no_bias,
    )
    generatorSymbol = mx.sym.Activation(g5, name="gact5", act_type="tanh")


# The discriminator module:
def discr_module():
    # creat the discriminator
    pass
<|endoftext|>
[{"Id": 14044587, "ScriptId": 3865422, "ParentScriptVersionId": NaN, "ScriptLanguageId": 9, "AuthorUserId": 1077425, "CreationDate": "05/11/2019 15:32:13", "VersionNumber": 1.0, "Title": "conditional_GAN_using_MXNet", "EvaluationDate": "05/11/2019", "IsChange": true, "TotalLines": 87.0, "LinesInsertedFromPrevious": 87.0, "LinesChangedFromPrevious": 0.0, "LinesUnchangedFromPrevious": 0.0, "LinesInsertedFromFork": NaN, "LinesDeletedFromFork": NaN, "LinesChangedFromFork": NaN, "LinesUnchangedFromFork": NaN, "TotalVotes": 0}]
[{"Id": 9146264, "KernelVersionId": 14044587, "SourceDatasetVersionId": 34877}]
[{"Id": 34877, "DatasetId": 27352, "DatasourceVersionId": 35935, "CreatorUserId": 1352634, "LicenseName": "CC0: Public Domain", "CreationDate": "05/19/2018 02:24:20", "VersionNumber": 2.0, "Title": "MNIST in CSV", "Slug": "mnist-in-csv", "Subtitle": "The MNIST dataset provided in a easy-to-use CSV format", "Description": "# The MNIST dataset provided in a easy-to-use CSV format\nThe [original dataset](http://yann.lecun.com/exdb/mnist/) is in a format that is difficult for beginners to use. This dataset uses the work of [Joseph Redmon](https://pjreddie.com/) to provide the [MNIST dataset in a CSV format](https://pjreddie.com/projects/mnist-in-csv/).\n\nThe dataset consists of two files:\n\n1. `mnist_train.csv`\n2. `mnist_test.csv`\n\nThe `mnist_train.csv` file contains the 60,000 training examples and labels. The `mnist_test.csv` contains 10,000 test examples and labels. Each row consists of 785 values: the first value is the label (a number from 0 to 9) and the remaining 784 values are the pixel values (a number from 0 to 255).", "VersionNotes": "Added column headers", "TotalCompressedBytes": 127943851.0, "TotalUncompressedBytes": 15970538.0}]
[{"Id": 27352, "CreatorUserId": 1352634, "OwnerUserId": 1352634.0, "OwnerOrganizationId": NaN, "CurrentDatasetVersionId": 34877.0, "CurrentDatasourceVersionId": 35935.0, "ForumId": 35558, "Type": 2, "CreationDate": "05/19/2018 00:53:44", "LastActivityDate": "05/19/2018", "TotalViews": 422443, "TotalDownloads": 111721, "TotalVotes": 678, "TotalKernels": 503}]
# # A conditional Conv-GAN using MXNet on the MNIST dataset
# ![image.png](attachment:image.png)
import numpy as np
import mxnet as mx
import pandas as pd
import matplotlib.pyplot as plt
import os

print(os.listdir("../input"))
# Any results you write to the current directory are saved as output.

# ## Figuring out the data format and making it usable
train_data_ = pd.read_csv("../input/mnist_train.csv")
test_data_ = pd.read_csv("../input/mnist_test.csv")
print(train_data_.head())
train_label = train_data_["label"]
test_label = test_data_["label"]
train_data = train_data_.drop(columns="label").values
test_data = test_data_.drop(columns="label").values
print(train_data.shape)


# ### Trying to recreate the images
def get_image(mat):
    mat = mat.reshape((28, 28))
    print(mat.shape)
    plt.imshow(mat, cmap="gray")
    plt.show


def get_sturctured_images(data):
    # convert to batch_size X width X height form
    data = data.reshape((-1, 28, 28))
    return data


# plot the image at this index:
idx = 4
get_image(train_data[idx])


#
# ***
# ## The Conditional Conv-GAN model
# The model specifics
ctx = mx.gpu(0)


# The Generator Module
def gen_module():
    # just create the generator module and return it
    # it would generate an image from some random number
    no_bias = True
    fix_gamma = True
    epsilon = 1e-5 + 1e-12
    rand = mx.sym.Variable("rand")
    g1 = mx.sym.Deconvolution(
        rand, name="g1", kernel=(4, 4), num_filter=1024, no_bias=no_bias
    )
    gbn1 = mx.sym.BatchNorm(g1, name="gbn1", fix_gamma=fix_gamma, eps=epsilon)
    gact1 = mx.sym.Activation(gbn1, name="gact1", act_type="relu")
    g2 = mx.sym.Deconvolution(
        gact1,
        name="g2",
        kernel=(4, 4),
        stride=(2, 2),
        pad=(1, 1),
        num_filter=512,
        no_bias=no_bias,
    )
    gbn2 = mx.sym.BatchNorm(g2, name="gbn2", fix_gamma=fix_gamma, eps=epsilon)
    gact2 = mx.sym.Activation(gbn2, name="gact2", act_type="relu")
    g3 = mx.sym.Deconvolution(
        gact2,
        name="g3",
        kernel=(4, 4),
        stride=(2, 2),
        pad=(1, 1),
        num_filter=256,
        no_bias=no_bias,
    )
    gbn3 = mx.sym.BatchNorm(g3, name="gbn3", fix_gamma=fix_gamma, eps=epsilon)
    gact3 = mx.sym.Activation(gbn3, name="gact3", act_type="relu")
    g4 = mx.sym.Deconvolution(
        gact3,
        name="g4",
        kernel=(4, 4),
        stride=(2, 2),
        pad=(1, 1),
        num_filter=128,
        no_bias=no_bias,
    )
    gbn4 = mx.sym.BatchNorm(g4, name="gbn4", fix_gamma=fix_gamma, eps=epsilon)
    gact4 = mx.sym.Activation(gbn4, name="gact4", act_type="relu")
    g5 = mx.sym.Deconvolution(
        gact4,
        name="g5",
        kernel=(4, 4),
        stride=(2, 2),
        pad=(1, 1),
        num_filter=3,
        no_bias=no_bias,
    )
    generatorSymbol = mx.sym.Activation(g5, name="gact5", act_type="tanh")


# The discriminator module:
def discr_module():
    # creat the discriminator
    pass
