Skip to content

Commit

Permalink
check ch15 in tf 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Jul 24, 2018
1 parent f9139e1 commit 0edb69b
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 168 deletions.
309 changes: 154 additions & 155 deletions code/ch15/ch15.ipynb

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions code/ch15/ch15.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# In[1]:


get_ipython().magic('load_ext watermark')
get_ipython().magic("watermark -a 'Sebastian Raschka & Vahid Mirjalili' -d -p numpy,scipy,tensorflow")
get_ipython().run_line_magic('load_ext', 'watermark')
get_ipython().run_line_magic('watermark', "-a 'Sebastian Raschka & Vahid Mirjalili' -d -p numpy,scipy,tensorflow")


# *The use of `watermark` is optional. You can install this IPython extension via "`pip install watermark`". For more information, please see*: https://github.com/rasbt/watermark.
Expand All @@ -42,7 +42,7 @@


from IPython.display import Image
get_ipython().magic('matplotlib inline')
get_ipython().run_line_magic('matplotlib', 'inline')


# In[3]:
Expand Down Expand Up @@ -114,7 +114,6 @@ def conv1d(x, w, p=0, s=1):
np.convolve(x, w, mode='same'))



# ### Performing a discrete convolution in 2D

# In[9]:
Expand Down Expand Up @@ -164,7 +163,6 @@ def conv2d(X, W, p=(0,0), s=(1,1)):
scipy.signal.convolve2d(X, W, mode='same'))



# ## Sub-sampling

# In[12]:
Expand Down Expand Up @@ -317,7 +315,7 @@ def batch_generator(X, y, batch_size=64,
std_val = np.std(X_train)

X_train_centered = (X_train - mean_vals)/std_val
X_valid_centered = X_valid - mean_vals
X_valid_centered = (X_valid - mean_vals)/std_val
X_test_centered = (X_test - mean_vals)/std_val

del X_data, y_data, X_train, X_valid, X_test
Expand Down Expand Up @@ -425,7 +423,7 @@ def fc_layer(input_tensor, name,
# In[23]:


def build_cnn():
def build_cnn(learning_rate=1e-4):
## Placeholders for X and y:
tf_x = tf.placeholder(tf.float32, shape=[None, 784],
name='tf_x')
Expand Down Expand Up @@ -580,8 +578,7 @@ def predict(sess, X_test, return_proba=False):
import tensorflow as tf
import numpy as np

## Define hyperparameters
learning_rate = 1e-4
## Define random seed
random_seed = 123

np.random.seed(random_seed)
Expand Down Expand Up @@ -907,10 +904,10 @@ def build(self):
logits=h4, labels=tf_y_onehot),
name='cross_entropy_loss')

## Optimizer:
## Optimizer
optimizer = tf.train.AdamOptimizer(self.learning_rate)
optimizer = optimizer.minimize(cross_entropy_loss,
name='train_op')
name='train_op')

## Finding accuracy
correct_predictions = tf.equal(
Expand Down Expand Up @@ -982,7 +979,6 @@ def predict(self, X_test, return_proba = False):




# In[33]:


Expand Down Expand Up @@ -1027,7 +1023,7 @@ def predict(self, X_test, return_proba = False):
#
# Readers may ignore the next cell.

# In[1]:
# In[ ]:


get_ipython().system(' python ../.convert_notebook_to_script.py --input ch15.ipynb --output ch15.py')
Expand Down

0 comments on commit 0edb69b

Please sign in to comment.