Commit 9cf69179 authored by Jacky Lin's avatar Jacky Lin
Browse files

add model saver

parent bf034f91
......@@ -418,5 +418,27 @@
%% Cell type:code id: tags:
 
``` python
 
```
%% Cell type:markdown id: tags:
#### Save/Load Model
%% Cell type:code id: tags:
``` python
# Save Model
torch.save(netG, "saved_models/generator.pth")
torch.save(netD, "saved_models/discriminator.pth")
```
%% Cell type:code id: tags:
``` python
# Load Model
netG = torch.load("saved_models/generator.pth")
netD = torch.load("saved_models/discriminator.pth")
netG.eval()
netD.eval()
```
This diff is collapsed.
......@@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
......@@ -39,7 +39,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -55,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
......@@ -78,13 +78,13 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e159505ae8b147fdab136d2c8e71539f",
"model_id": "66ab8e3d491f40b6a1eb73ad62c1ca3e",
"version_major": 2,
"version_minor": 0
},
......
......@@ -47,3 +47,4 @@ pip install pytorch numpy pandas sklearn torchvision matplotlib plotly PIL tqdm
4. [DCGAN](https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html)
5. [Context-Encoder GAN for Image Inpainting](https://www.kaggle.com/balraj98/context-encoder-gan-for-image-inpainting-pytorch/output)
6. [Tiny ImageNet Kaggle](https://www.kaggle.com/akash2sharma/tiny-imagenet)
7. [GANs-Application](https://github.com/nashory/gans-awesome-applications)
......@@ -3,16 +3,25 @@
##### ref https://realpython.com/generative-adversarial-networks/#your-first-gan
%% Cell type:markdown id: tags:
## Simple GANs Example
%% Cell type:markdown id: tags:
#### Introduction
This project focuses on the exploration of generative adversarial network (GAN). A [generative adversarial network (GAN)](https://en.wikipedia.org/wiki/Generative_adversarial_network) is a class of machine learning frameworks designed by Ian Goodfellow and his colleagues in 2014. Two neural networks contest with each other in a game in the form of a zero-sum game, where one agent's gain is another agent's loss. In this project, we explore the basic concepts and structures behind the generative adversarial networks. We also perform this neural network on different datasets to learn some interesting application of this model. All the code we provided is written in python3 in jupyter notebook.
%% Cell type:markdown id: tags:
This notebook give an example of GANs where we train neural networks to generating a sine function $f(x) = sin(x)$ given a series of random number
%% Cell type:markdown id: tags:
### Import the essentail pacakge
First we import the essentail package, including:
### Import the essential pacakge
First we import the essential package, including:
1. pytorch which is the mainly package to build neural structure
2. matplotlib is used to visualize the data
%% Cell type:code id: tags:
......@@ -80,11 +89,12 @@
#### Build the model
%% Cell type:markdown id: tags:
The GANs consists of two neural networks, one called Discriminator and the other called Generator. The role of the generator is to estimate the probability distribution of the real samples in order to provide generated samples resembling real data. The discriminator, in turn, is trained to estimate the probability that a given sample came from the real data rather than being provided by the generator.
![Struct](img/GANsStruct.jpg)
![s](./img/GANsStruct.jpg)
%% Cell type:code id: tags:
``` python
class Discriminator(nn.Module):
......@@ -158,12 +168,10 @@
%% Cell type:markdown id: tags:
#### Set the optimization object
What do optimizer do in neural network?
![op](img/optim.png)
`Adam` combines the best properties of the AdaGrad and RMSProp algorithms to provide an optimization algorithm that can handle sparse gradients on noisy problems.
%% Cell type:code id: tags:
``` python
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment