Giter Club home page Giter Club logo

advanced-applied-deep-learning's Introduction

Apress Source Code

This repository accompanies Advanced Applied Deep Learning by Umberto Michelucci (Apress, 2019).

Cover image

Download the files as a zip using the green button, or clone the repository to your machine using Git.

Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

Contributions

See the file Contributing.md for more information on how you can contribute to this repository.

advanced-applied-deep-learning's People

Contributors

michelucci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

advanced-applied-deep-learning's Issues

Renamed file and library version error

Sir,
In chapter 5 - Neural Style Transfer

These errors are on both 2 notebooks -

glass.jpg is renamed to mosaic.jpg (but not in code, thus causing file not found)

AND

!pip install tensorflow-gpu==2.0.0-alpha0
This line is causing error in Colab, without it works fine.

Rest works fine.

Folders Missing

In Chapter 4 - Transfer Learning

These data folders are missing -
1.train
2.validation_data

Thus causing error in whole code

Enabling Eager Execution

import tensorflow as tf
tf.enable_eager_execution()

book shows this code but it errors out.
i guess in Colab it's already installed

[ISSUE] In source codes, there is no plt show codes about chess board

Issue

image

Fixed issue

# Output chess board image (chess board image)
import numpy as np
import matplotlib.pyplot as plt

chessboard  = np.zeros([8*20,8*20])
for row in range(0,8):
    for column in range(0,8):
        if((column+8*row) % 2 ==1) and (row % 2 == 0):
            chessboard[row*20:row*20+20,column*20:column*20+20] = 1
        elif((column+8*row) % 2 ==0) and (row % 2 == 1):
            chessboard[row*20:row*20+20,column*20:column*20+20] = 1

#set the plot's title.
#plt.title('Chess Board')

plt.xlim(xmin=0,xmax=160)
plt.ylim(ymin=0,ymax=160)

plt.imshow(chessboard,cmap='binary_r')
# Print the chart
plt.show()

image

image

[ISSUE] About The Book FeedBack And The Program Environments Introduction(Python:3.6.13,3.7.16;TensorFlow:1.13.1,2.3.0)

About This Book

This book is perfect book. It is the author's painstaking work and will be remembered by us in the long river of history!
Thanks @michelucci !

The Program Environments

In Chapter 1,2,3,4,6, please use python=3.6.13, tensorflow==1.13.1 environment

  • Use conda install environment(Windows)
conda deactivate
conda remove -y --name tensorflow-gpu-keras --all
conda create -y --name tensorflow-gpu-keras python=3.6.13
activate tensorflow-gpu-keras
python -V

conda install -y tensorflow-gpu==1.13.1
conda install -y keras

REM Install matplotlib
conda install -y matplotlib

REM Failed to import `pydot`
conda install -y pydot

REM Install cv2(opencv)
conda install -y opencv

REM Install sklearn
conda install -y scikit-learn

REM Install pandas
conda install -y pandas

REM Install seaborn
conda install -y seaborn

REM Install scikit-image
conda install -y scikit-image

conda deactivate

In Chapter 5,7,8, please use python=3.7.16, tensorflow==2.3.0 environment

  • Use conda install environment(Windows)
conda deactivate
conda remove -y --name tensorflow-2.3.0-gpu-keras --all
conda create -y --name tensorflow-2.3.0-gpu-keras python=3.7.16
activate tensorflow-2.3.0-gpu-keras
python -V

conda install -y tensorflow-gpu==2.3.0
conda install -y keras

REM Install matplotlib
conda install -y matplotlib

REM Failed to import `pydot`
conda install -y pydot

REM Install cv2(opencv)
conda install -y opencv

REM Install sklearn
conda install -y scikit-learn

REM Install pandas
conda install -y pandas

REM Install seaborn
conda install -y seaborn

REM Install scikit-image
conda install -y scikit-image
conda deactivate

Missing image in Chapter 4

Hello,

Great book ... been absorbing the info as quickly as I can!

I did notice that "elephant.jpg" from Chapter 4 (as referred to on page 143) seems to be missing from the github repo.

Or at least, I have not been able to find it.

Cheers,
Ion-Drive

[ISSUE] In page 32 of this book, the y should be y_noise

@michelucci ,
In page 32 of this book, the y should be y_noise.
image

The corrected codes:

for i in range(iters):
    optimizer.apply_gradients(grad(model,x,y_noise))
    if i % 1000 == 0:
        print("Iteration {}, loss: {}".format(i+1, loss(model,x,y_noise).numpy()))

@michelucci ,
Your Chinese book ‘深度学习进阶,卷积神经网络和对象检测’, it also contains the same error.
Do you afford the Chinese book‘s translators' emails? Yang Tao and Yanan Li. Thanks!

[ISSUE][HOW TO FIX] InvalidArgumentError: cannot compute MatMul as input #0(zero-based) was expected to be a float tensor but is a uint8 tensor [Op:MatMul]

@michelucci ,
Your book is perfect! Thank you!

Here, I found a issue, I have fixed it. I posted the fixed method.
In tensorflow 1.13.1, I run your code, a issue encountered.

Original Code

import tensorflow as tf
import keras
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('default')

import tensorflow.contrib.eager as tfe

#from google.colab import files

tf.enable_eager_execution()

num_classes = 10

mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()

image_vector_size = 28*28
x_train = x_train.reshape(x_train.shape[0], image_vector_size).astype('float32')
x_test = x_test.reshape(x_test.shape[0], image_vector_size).astype('float32')

y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

dataset = tf.data.Dataset.from_tensor_slices(
    (tf.cast(x_train/255.0, tf.float32),
     tf.cast(y_train,tf.int64)))

dataset = dataset.shuffle(60000).batch(64)

mnist_model = tf.keras.Sequential([
  tf.keras.layers.Dense(1024, input_shape=(784,)),  # must declare input shape
  tf.keras.layers.Dense(1024),  # must declare input shape
  tf.keras.layers.Dense(10)
])

optimizer = tf.train.AdamOptimizer()
loss_history = []

#%%time
with tf.device('/cpu:0'):
  for i in range(1): # Loop for the Epochs
    print ("\nEpoch:", i)
    for (batch, (images, labels)) in enumerate(dataset.take(60000)): # Loop for the mini-batches
      if batch % 100 == 0:
        print('.', end='')
      with tf.GradientTape() as tape:
        logits = mnist_model(images, training=True)
        loss_value = tf.losses.sparse_softmax_cross_entropy(tf.argmax(labels, axis = 1), logits)

        loss_history.append(loss_value.numpy())
        grads = tape.gradient(loss_value, mnist_model.variables)
        optimizer.apply_gradients(zip(grads, mnist_model.variables),
                                  global_step=tf.train.get_or_create_global_step())
        
probs = tf.nn.softmax(mnist_model(x_train))
print(tf.reduce_mean(tf.cast(tf.equal(tf.argmax(probs, axis=1), tf.argmax(y_train, axis = 1)), tf.float32)))

Output

Epoch: 0
..........
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-4-6753e0f3f94f> in <module>
     54                                   global_step=tf.train.get_or_create_global_step())
     55 
---> 56 probs = tf.nn.softmax(mnist_model(x_train))
     57 print(tf.reduce_mean(tf.cast(tf.equal(tf.argmax(probs, axis=1), tf.argmax(y_train, axis = 1)), tf.float32)))

D:\ProgramData\Anaconda3\envs\tensorflow-gpu-keras\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
    590       else:
    591         # Eager execution on data tensors.
--> 592         outputs = self.call(inputs, *args, **kwargs)
    593         self._handle_activity_regularization(inputs, outputs)
    594         return outputs

D:\ProgramData\Anaconda3\envs\tensorflow-gpu-keras\lib\site-packages\tensorflow\python\keras\engine\sequential.py in call(self, inputs, training, mask)
    228   def call(self, inputs, training=None, mask=None):
    229     if self._is_graph_network:
--> 230       return super(Sequential, self).call(inputs, training=training, mask=mask)
    231 
    232     outputs, _ = self._call_and_compute_mask(

D:\ProgramData\Anaconda3\envs\tensorflow-gpu-keras\lib\site-packages\tensorflow\python\keras\engine\network.py in call(self, inputs, training, mask)
    813     outputs, _ = self._run_internal_graph(inputs,
    814                                           training=training,
--> 815                                           mask=masks)
    816     return outputs
    817 

D:\ProgramData\Anaconda3\envs\tensorflow-gpu-keras\lib\site-packages\tensorflow\python\keras\engine\network.py in _run_internal_graph(self, inputs, training, mask)
    998               else:
    999                 if context.executing_eagerly():
-> 1000                   output_tensors = layer(computed_tensor, **kwargs)
   1001                 else:
   1002                   output_tensors = layer.call(computed_tensor, **kwargs)

D:\ProgramData\Anaconda3\envs\tensorflow-gpu-keras\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
    590       else:
    591         # Eager execution on data tensors.
--> 592         outputs = self.call(inputs, *args, **kwargs)
    593         self._handle_activity_regularization(inputs, outputs)
    594         return outputs

D:\ProgramData\Anaconda3\envs\tensorflow-gpu-keras\lib\site-packages\tensorflow\python\keras\layers\core.py in call(self, inputs)
    973         outputs.set_shape(output_shape)
    974     else:
--> 975       outputs = gen_math_ops.mat_mul(inputs, self.kernel)
    976     if self.use_bias:
    977       outputs = nn.bias_add(outputs, self.bias)

D:\ProgramData\Anaconda3\envs\tensorflow-gpu-keras\lib\site-packages\tensorflow\python\ops\gen_math_ops.py in mat_mul(a, b, transpose_a, transpose_b, name)
   5321       else:
   5322         message = e.message
-> 5323       _six.raise_from(_core._status_to_exception(e.code, message), None)
   5324   # Add nodes to the TensorFlow graph.
   5325   if transpose_a is None:

D:\ProgramData\Anaconda3\envs\tensorflow-gpu-keras\lib\site-packages\six.py in raise_from(value, from_value)

InvalidArgumentError: cannot compute MatMul as input #0(zero-based) was expected to be a float tensor but is a uint8 tensor [Op:MatMul]

How to fix

Modify

x_train = x_train.reshape(x_train.shape[0], image_vector_size)
x_test = x_test.reshape(x_test.shape[0], image_vector_size)

To

x_train = x_train.reshape(x_train.shape[0], image_vector_size).astype('float32')
x_test = x_test.reshape(x_test.shape[0], image_vector_size).astype('float32')

After fixed, Output

Epoch: 0
..........tf.Tensor(0.88195, shape=(), dtype=float32)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.