|
1 | 1 | from __future__ import print_function
|
2 | 2 | from __future__ import absolute_import
|
3 | 3 |
|
4 |
| -# use: https://github.com/tensorflow/docs/blob/master/site/en/r1/tutorials/sequences/audio_recognition.md |
5 |
| -# https://github.com/tensorflow/docs/blob/master/site/en/r1/tutorials/sequences/audio_recognition.md |
6 |
| -# we now use: https://www.youtube.com/watch?v=9dXiAecyJrY&feature=youtu.be&t=13874 |
| 4 | +# https://medium.com/startup-grind/fueling-the-ai-gold-rush-7ae438505bc2 |
| 5 | +# https://www.analyticsinsight.net/best-computer-vision-courses-to-master-in-2019/ |
| 6 | +# UCI data: https://archive.ics.uci.edu/ml/datasets/Human+Activity+Recognition+Using+Smartphones |
| 7 | +# Human Activity Recognition Using Smartphones Data Set, archive.ics.uci.edu, Human Activity Recognition |
| 8 | +# https://www.cfasociety.org/cleveland/Lists/Events%20Calendar/Attachments/1045/BIG-Data_AI-JPMmay2017.pdf |
7 | 9 |
|
8 | 10 | import numpy as np
|
| 11 | +import numpy.random |
9 | 12 | import pandas as pd
|
10 |
| -import sys, sklearn |
11 | 13 |
|
12 |
| -import numpy.random |
| 14 | +import sys, sklearn |
13 | 15 | import scipy.stats as ss
|
14 | 16 | import os, tarfile, errno
|
15 | 17 | import matplotlib.pyplot as plt
|
16 | 18 |
|
| 19 | +# https://www.cmegroup.com/education/files/jpm-momentum-strategies-2015-04-15-1681565.pdf |
| 20 | +# https://faculty.sites.uci.edu/pjorion/files/2018/05/JPM-2017-MachineLearningInvestments.pdf |
| 21 | +# we use: https://www.cmegroup.com/education/files/jpm-momentum-strategies-2015-04-15-1681565.pdf |
| 22 | +# https://www.cfasociety.org/cleveland/Lists/Events%20Calendar/Attachments/1045/BIG-Data_AI-JPMmay2017.pdf |
| 23 | + |
17 | 24 | import tensorflow as tf
|
18 | 25 | print(tf.__version__) # 1.14.0
|
19 | 26 | import matplotlib.pyplot as plt
|
20 | 27 | import seaborn as sns; sns.set()
|
21 | 28 |
|
22 |
| -# https://medium.com/startup-grind/fueling-the-ai-gold-rush-7ae438505bc2 |
23 |
| -# https://www.analyticsinsight.net/best-computer-vision-courses-to-master-in-2019/ |
24 |
| -# UCI data: https://archive.ics.uci.edu/ml/datasets/Human+Activity+Recognition+Using+Smartphones |
25 |
| -# Human Activity Recognition Using Smartphones Data Set, archive.ics.uci.edu, Human Activity Recognition |
26 |
| -# https://www.cfasociety.org/cleveland/Lists/Events%20Calendar/Attachments/1045/BIG-Data_AI-JPMmay2017.pdf |
| 29 | +# use: https://github.com/tensorflow/docs/blob/master/site/en/r1/tutorials/sequences/audio_recognition.md |
| 30 | +# https://github.com/tensorflow/docs/blob/master/site/en/r1/tutorials/sequences/audio_recognition.md |
| 31 | +# we now use: https://www.youtube.com/watch?v=9dXiAecyJrY&feature=youtu.be&t=13874 |
27 | 32 |
|
28 | 33 | if sys.version_info >= (3, 0, 0):
|
29 | 34 | import urllib.request as urllib
|
|
68 | 73 | from matplotlib import pyplot as plt
|
69 | 74 | import torchvision.transforms as transforms
|
70 | 75 |
|
71 |
| -#import renom as rm |
72 |
| -from copy import deepcopy |
73 |
| -import matplotlib.pyplot as plt |
74 |
| - |
75 | 76 | import numpy as np
|
| 77 | +#import renom as rm |
76 | 78 | import tensorflow as tf
|
| 79 | +from copy import deepcopy |
77 | 80 | from keras.layers import Dense
|
| 81 | +import matplotlib.pyplot as plt |
78 | 82 | from keras.datasets import mnist
|
79 | 83 | from keras.models import Sequential
|
80 | 84 |
|
81 | 85 | # https://www.renom.jp/notebooks/tutorial/generative-model/anoGAN/notebook.html
|
82 | 86 | # use: https://www.renom.jp/notebooks/tutorial/generative-model/anoGAN/notebook.html
|
83 | 87 |
|
84 |
| -import external.renom as rm |
| 88 | +import externals.renom as rm |
85 | 89 | #from renom.optimizer import Adam
|
86 | 90 | #from renom.cuda import set_cuda_active
|
87 |
| -from external.renom.optimizer import Adam |
88 |
| -from external.renom.cuda import set_cuda_active |
| 91 | +from externals.renom.optimizer import Adam |
| 92 | +from externals.renom.cuda import set_cuda_active |
89 | 93 |
|
90 | 94 | # MNIST: Keras or scikit-learn embedded datasets
|
91 | 95 | # Keras: from keras.datasets import mnist
|
@@ -274,7 +278,7 @@ def forward(self, X):
|
274 | 278 | return y4
|
275 | 279 |
|
276 | 280 | # Backward propagation
|
277 |
| - def backward(self, X, l, y4): |
| 281 | + def backward(self, X, l, y4): # Back, Backward |
278 | 282 | # Derivative of binary cross entropy cost w.r.t. final output y4
|
279 | 283 | self.dC_dy4 = y4 - l
|
280 | 284 |
|
@@ -435,9 +439,8 @@ def train(self, epochs, batch_size=128, save_interval=50):
|
435 | 439 | idx = np.random.randint(0, X_train.shape[0], half_batch)
|
436 | 440 | imgs = X_train[idx]
|
437 | 441 |
|
| 442 | + # Generator => Generate a half batch of new images |
438 | 443 | noise = np.random.normal(0, 1, (half_batch, 100))
|
439 |
| - |
440 |
| - # Generate a half batch of new images |
441 | 444 | gen_imgs = self.generator.predict(noise)
|
442 | 445 |
|
443 | 446 | # Train the Discriminator
|
@@ -1586,10 +1589,8 @@ def define_discriminator(in_shape=(32, 32, 3)):
|
1586 | 1589 | # we use: https://machinelearningmastery.com/how-to-develop-a-generative-adversarial-network-for-a-cifar-10-small-object-photographs-from-scratch/
|
1587 | 1590 |
|
1588 | 1591 | (trainX, _), (_, _) = load_data() # load the CIFAR-10 dataset
|
1589 |
| -X = trainX.astype('float32') # convert from unsigned ints to floats |
1590 |
| - |
1591 |
| -# scale from [0,255] to [-1,1] |
1592 |
| -X = (X - 127.5) / 127.5 |
| 1592 | +X = trainX.astype('float32') # convert from ints to floats |
| 1593 | +X = (X - 127.5) / 127.5 # scale from [0,255] to [-1,1] |
1593 | 1594 |
|
1594 | 1595 | # load and prepare CIFAR-10 training images
|
1595 | 1596 | def load_real_samples():
|
@@ -5575,10 +5576,9 @@ def build(width, height, depth, classes):
|
5575 | 5576 | # ReLU is the most common activation function. We use ReLU.
|
5576 | 5577 | # Mean across a batch. We use batches. Normalize across a batch.
|
5577 | 5578 |
|
| 5579 | +# https://github.com/life-efficient/Academy-of-AI/blob/master/Lecture%2013%20-%20Generative%20Models/GANs%20tutorial.ipynb |
5578 | 5580 | # use: https://github.com/life-efficient/Academy-of-AI/blob/master/Lecture%2013%20-%20Generative%20Models/GANs%20tutorial.ipynb
|
5579 | 5581 |
|
5580 |
| - |
5581 |
| - |
5582 | 5582 | import torch
|
5583 | 5583 | import torchvision
|
5584 | 5584 |
|
|
0 commit comments