Files
notes_estom/Tensorflow/TensorFlow2.0/044.md
yinkanglong_lab 68c2dbc3ac apacheCNml&dl
2021-03-20 16:02:39 +08:00

1.5 KiB

Transfer learning with TensorFlow Hub

原文:https://tensorflow.google.cn/tutorials/images/transfer_learning_with_hub

TensorFlow Hub is a repository of pre-trained TensorFlow models.

This tutorial demonstrates how to:

  1. Use models from TensorFlow Hub with 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

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 to load a MobileNetV2 model from TensorFlow Hub. Any compatible image classifier model from hub.tensorflow.google.cn will work here.

Toggle code
classifier_model ="https://hub.tensorflow.google.cn/google/tf2-preview/mobilenet_v2/classification/4"