详细内容或原文请订阅后点击阅览
tfhub:TensorFlow Hub 的 R 接口
TensorFlow Hub 是一个用于发布、发现和使用机器学习模型可重用部分的库。模块是 TensorFlow 图的一个独立部分,连同其权重和资产,可以在称为迁移学习的过程中在不同任务中重复使用。
来源:RStudio AI博客我们很高兴地宣布,tfhub 的第一个版本现已在 CRAN 上发布。tfhub 是 TensorFlow Hub 的 R 接口 - 用于发布、发现和使用机器学习模型可重用部分的库。模块是 TensorFlow 图的独立部分,连同其权重和资产,可以在称为迁移学习的过程中在不同任务之间重复使用。
tfhub可以使用以下命令安装 tfhub 的 CRAN 版本:
安装 R 包后,您需要安装 TensorFlow Hub python 包。您可以通过运行以下命令完成此操作:
入门
tfhub 的基本功能是 layer_hub,其工作方式与 keras 层相同,但允许您加载完整的预训练深度学习模型。
layer_hub
keras
例如,您可以:
library(tfhub)layer_mobilenet <- layer_hub( handle = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4")
library(tfhub)layer_mobilenet <- layer_hub( handle = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4")
library(tfhub)
library
library
(
tfhub
tfhub
)
layer_mobilenet <- layer_hub(
layer_mobilenet
<-
layer_hub
(
handle = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4"
=
"https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4"
)
)
这将下载在 ImageNet 数据集上预先训练的 MobileNet 模型。tfhub 模型在本地缓存,下次使用同一模型时无需下载。
您现在可以将 layer_mobilenet 用作通常的 Keras 层。例如,您可以定义一个模型:
layer_mobilenet
library(keras)input <- layer_input(shape = c(224, 224, 3))output <- layer_mobilenet(input)model <- keras_model(input, output)summary(model)
library(keras)input <- layer_input(shape = c(224, 224, 3))output <- layer_mobilenet(input)model <- keras_model(input, output)summary(model)
library(keras)
library
library
(
keras
keras
)
input <- layer_input(shape = c(224, 224, 3))
输入
<-
layer_input
(
=
c
c
(
224
224
3
)
)
输出 <- layer_mobilenet(输入)
输出
<-
layer_mobilenet
(
输入
)
模型
<-
(
)
(
)
(