[TensorFlow Certification Day5] Convolutional Neural Networks in TensorFlow Week1/2/3 (5hrs)


Posted by Kled on 2020-08-18

結果搞錯了, 我以為 tensorflow in practice跟先前的 introduction tensorflow是兩堂課

重新看才發現tensorflow in practice裡面包含了四大課程

  1. Introduction to TensorFlow for Artificial Intelligence, Machine Learning, and Deep Learning
  2. Convolutional Neural Networks in TensorFlow
  3. Natural Language Processing in TensorFlow
  4. Sequences, Time Series and Prediction

因此接下來要上的就是

Convolutional Neural Networks in TensorFlow

Week1 Exploring a Larger Dataset

教使用貓狗數據集來做, 光是cropping就可以讓判斷錯誤的貓變成正確,
裡面再次提倡可視化的重要性
題目不難, 習題也不難

Week2 Augumentation : A technique to avoid overfitting

這裡主要在教argumentation, 因為當data不夠的時候, 可能要透過argumentation來補足training data的不足, 例如 : 只有左邊的臉, 而沒有右邊的臉, 但可以透過鏡射達到這件事, 這裡教的argumentation不是直接修改raw data, 而是直接使用之前使用過的ImageDataGenerator
裡面包含了zoom_range, width_shift_range, height_shift_range, shear_range(透視拉扯的那種感覺), rotation_range, horizontal_flip

#這裡有各種keras提供的API去load data
from keras import preprocessing
#還可以做Argumentation
tf.keras.preprocessing.image.ImageDataGenerator(
    featurewise_center=False,
    samplewise_center=False,
    featurewise_std_normalization=False,
    samplewise_std_normalization=False,
    zca_whitening=False,
    zca_epsilon=1e-06,
    rotation_range=0,
    width_shift_range=0.0,
    height_shift_range=0.0,
    brightness_range=None,
    shear_range=0.0,
    zoom_range=0.0,
    channel_shift_range=0.0,
    fill_mode="nearest",
    cval=0.0,
    horizontal_flip=False,
    vertical_flip=False,
    rescale=None,
    preprocessing_function=None,
    data_format=None,
    validation_split=0.0,
    dtype=None,
)

但要特別注意, 有些情況是不管怎麼argumentation都不出來的, 例如只有側面的臉, 但是test出現正面的臉, 那就不是透過argumentation可以得到的feature, 這時候就要使用transfer learning

Week3 Transfer Learning

這個部份的Exercise我遇到了很多坑
還是先介紹一下transfer learning做甚麼用的
如同前面說的, 當數據很小的時候, 即使argumentation也沒辦法extract更多的feature, 如果只有一部分的數據很難學會所有的feature, 但是從別人訓練過的可以把這些知識下載下來, 可以更快速的開始
tensorflow裡面可以下載模型, 設置為可訓練, 凍結或鎖定這些layer來做transfer learning
可以把一些較後面的層拿掉重新訓練, 因為他可能也是fit這些data的feature, 然後把前面的layer所定下來
但是這樣訓練之後, 發現還是overfitting了, 要怎麼解決呢?
dropout的用意是NN裡面可能有相似的weight, 彼此之間會互相影響, 導致overfitting

Exercise要特別注意幾個坑, 尤其是batch_size很多人一樣遇到這個問題

#1. input_shape如果不設, 後續的conv2D都會是None, None, None, x
#2. weights=None, 不設的話會變成去download imagenet, 這在coursera課程會失敗
pre_trained_model = InceptionV3(input_shape=(150,150,3), include_top=False, weights = None)# Your Code Here
#3. Memory Size Not Enough, 把batch_size調小
#4. 把 steps_pe_epoch調大
train_generator = train_datagen.flow_from_directory(
    train_dir,  # This is the source directory for training images
    target_size=(150, 150),  # All images will be resized to 150x150
    batch_size=10,
    # Since we use binary_crossentropy loss, we need binary labels
    class_mode='binary')

看起來這幾個單元都在教大家怎麼解overfitting, 並沒有特別難懂的東西, 大多數時間都花在Week 3的Exercise
考試之前真的要把這幾個jupyter存起來, 否則5hrs的考試時間連找都來不及找


#AI #人工智慧 #tensorFlow Certification #TensorFlow #machine learning #機器學習







Related Posts

Fetch 與 Promise (三):注意事項

Fetch 與 Promise (三):注意事項

Object and Arrays - Reference VS Copy

Object and Arrays - Reference VS Copy

七天帶你初探AR世界-Day 7

七天帶你初探AR世界-Day 7


Comments