迁移学习包括:
1、Feature Extraction
2、Fine-Tuning
本文基于 tensorflow2.0,使用 cats_vs_dog 数据集,应用 tf.keras.applications 创建 base model,使用 ResNet101 做 Feature Extraction。
核心代码:
'''
Transfer learning with a pretrained ConvNet: resnet101
参考:
https://tensorflow.google.cn
下载模型位置:
~/.keras/models/resnet101_weights_tf_dim_ordering_tf_kernels_notop.h5
'''
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
keras = tf.keras
#dataset
#Data preprocessing
#Data download
#Use TensorFlow Datasets to load the cats and dogs dataset.
import tensorflow_datasets as tfds
tfds.disable_progress_