DL之VGG16:基于VGG16(Keras)利用Knifey-Spoony数据集对网络架构进行迁移学习(二)

简介: DL之VGG16:基于VGG16(Keras)利用Knifey-Spoony数据集对网络架构进行迁移学习

设计思路

1、基模型

image.png


2、思路导图

image.png


核心代码

 

model_VGG16.summary()                              

transfer_layer = model_VGG16.get_layer('block5_pool')    

print('transfer_layer.output:', transfer_layer.output)  

conv_model = Model(inputs=model_VGG16.input,

                  outputs=transfer_layer.output)

VGG16_TL_model = Sequential()                        # Start a new Keras Sequential model.

VGG16_TL_model.add(conv_model)                       # Add the convolutional part of the VGG16 model from above.

VGG16_TL_model.add(Flatten())                        # Flatten the output of the VGG16 model because it is from a convolutional layer.

VGG16_TL_model.add(Dense(1024, activation='relu'))   # Add a dense (aka. fully-connected) layer. This is for combining features that the VGG16 model has recognized in the image.

VGG16_TL_model.add(Dropout(0.5))                     # Add a dropout-layer which may prevent overfitting and improve generalization ability to unseen data e.g. the test-set.

VGG16_TL_model.add(Dense(num_classes, activation='softmax'))  # Add the final layer for the actual classification.

print_layer_trainable()

conv_model.trainable = False

for layer in conv_model.layers:

   layer.trainable = False

print_layer_trainable()  

loss = 'categorical_crossentropy'  

metrics = ['categorical_accuracy']

VGG16_TL_model.compile(optimizer=optimizer, loss=loss, metrics=metrics)      

epochs = 20

steps_per_epoch = 100

history = VGG16_TL_model.fit_generator(generator=generator_train,

                                 epochs=epochs,

                                 steps_per_epoch=steps_per_epoch,

                                 class_weight=class_weight,

                                 validation_data=generator_test,

                                 validation_steps=steps_test)

plot_training_history(history)  

VGG16_TL_model_result = VGG16_TL_model.evaluate_generator(generator_test, steps=steps_test)

print("Test-set classification accuracy: {0:.2%}".format(VGG16_TL_model_result[1]))


相关文章
|
3月前
|
Dubbo Java 应用服务中间件
Apache ShenYu 架构学习指南
Apache ShenYu 是一款高性能、插件化的微服务API网关,基于Spring WebFlux + Reactor 构建,支持多协议、动态配置与实时数据同步。本指南以通俗类比和实战路径,带你深入理解其架构设计、核心流程与源码实现,助力快速掌握并参与贡献。
584 12
|
3月前
|
Kubernetes Go API
Kubeflow-Model-Registry-架构学习指南
Kubeflow Model Registry 是一个用于管理机器学习模型元数据的基础设施,采用 Go、Python、React 和 Kubernetes 技术栈,支持模型版本、注册与存储追踪。本指南系统解析其分层架构、核心流程与代码结构,提供从环境搭建到贡献代码的完整学习路径,助力开发者深入掌握模型管理实践。
267 0
|
3月前
|
Kubernetes Go 调度
Kubeflow-Trainer-架构学习指南
本指南系统解析Kubeflow Trainer架构,涵盖核心设计、目录结构与代码逻辑,结合学习路径与实战建议,助你掌握这一Kubernetes原生机器学习训练平台的原理与应用。
601 139
|
3月前
|
Kubernetes API 开发工具
Kubeflow-Pipelines-架构学习指南
本指南带你深入 Kubeflow Pipelines 架构,从零掌握 ML 工作流编排。涵盖核心组件、代码结构、开发调试及贡献流程,结合实战练习与学习路径,助你由使用者进阶为贡献者。
525 139
|
3月前
|
Kubernetes Cloud Native Go
Kubeflow-KServe-架构学习指南
KServe是基于Kubernetes的生产级AI推理平台,支持多框架模型部署与管理。本指南从架构解析、代码结构到实战部署,系统讲解其核心组件如InferenceService、控制器模式及与Knative、Istio集成原理,并提供学习路径与贡献指南,助你快速掌握云原生AI服务技术。
654 139
|
3月前
|
并行计算 PyTorch 算法框架/工具
vLLM 架构学习指南
本指南深入解析vLLM高性能推理引擎架构,涵盖核心创新PagedAttention与连续批处理技术,结合代码结构、学习路径与实践建议,系统指导用户从入门到贡献源码的全过程。
1386 2
vLLM 架构学习指南
|
3月前
|
负载均衡 Java API
grpc-java 架构学习指南
本指南系统解析 grpc-java 架构,涵盖分层设计、核心流程与源码结构,结合实战路径与调试技巧,助你从入门到精通,掌握高性能 RPC 开发精髓。
395 7