迁移学习
1. 迁移学习的定义
指利用现有的模型,并根据新的应用场景稍加修改。不需要从头开始学。
![]()
图1-1 最近几年准确率越来越高的网络 |
为了使用迁移学习
![]()
|
![]()
|
2. Coading
在TensorFlow Hub(https://www.tensorflow.org/hub) 中具有很多已经训练好的模型。
!pip install "tensorflow_hub==0.4.0" !pip install "tf-nightly" import tensorflow as tf import tensorflow_hub as hub tf.enable_eager_execution() module_url = "https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1" embed = hub.KerasLayer(module_url) embeddings = embed(["A long sentence.", "single-word", "http://example.com"]) print(embeddings.shape) #(3,128)
第一步: 导入数据包
from __future__ import absolute_import, division, print_function, unicode_literals import tensorflow as tf import matplotlib.pylab as plt import tensorflow_hub as hub import tensorflow_datasets as tfds from tensorflow.keras import layers import logging logger = tf.get_logger() logger.setLevel(logging.ERROR)