mirror of
https://github.com/Estom/notes.git
synced 2026-04-05 03:48:56 +08:00
38 lines
1.5 KiB
Markdown
38 lines
1.5 KiB
Markdown
# Transfer learning with TensorFlow Hub
|
|
|
|
> 原文:[https://tensorflow.google.cn/tutorials/images/transfer_learning_with_hub](https://tensorflow.google.cn/tutorials/images/transfer_learning_with_hub)
|
|
|
|
[TensorFlow Hub](https://hub.tensorflow.google.cn/) is a repository of pre-trained TensorFlow models.
|
|
|
|
This tutorial demonstrates how to:
|
|
|
|
1. Use models from TensorFlow Hub with [`tf.keras`](https://tensorflow.google.cn/api_docs/python/tf/keras)
|
|
2. Use an image classification model from TensorFlow Hub
|
|
3. Do simple transfer learning to fine-tune a model for your own image classes
|
|
|
|
## Setup
|
|
|
|
```py
|
|
import numpy as np
|
|
import time
|
|
|
|
import PIL.Image as Image
|
|
import matplotlib.pylab as plt
|
|
|
|
import tensorflow as tf
|
|
import tensorflow_hub as hub
|
|
```
|
|
|
|
## An ImageNet classifier
|
|
|
|
You'll start by using a pretrained classifer model to take an image and predict what it's an image of - no training required!
|
|
|
|
### Download the classifier
|
|
|
|
Use [`hub.KerasLayer`](https://tensorflow.google.cn/hub/api_docs/python/hub/KerasLayer) to load a [MobileNetV2 model](https://hub.tensorflow.google.cn/google/tf2-preview/mobilenet_v2/classification/2) from TensorFlow Hub. Any [compatible image classifier model](https://hub.tensorflow.google.cn/s?q=tf2&module-type=image-classification) from hub.tensorflow.google.cn will work here.
|
|
|
|
<section class="expandable"><button type="button" class="button-red button expand-control">Toggle code</button></section>
|
|
|
|
```py
|
|
classifier_model ="https://hub.tensorflow.google.cn/google/tf2-preview/mobilenet_v2/classification/4"
|
|
``` |