5, Data Augmentation

Intro

这是深度学习第5课

在本课程结束时,您将能够使用数据增强。 这个技巧让你看起来拥有的数据远远超过实际拥有的数据,从而产生更好的模型。

 

Lesson

[1]

from IPython.display import YouTubeVideo
YouTubeVideo('ypt_BAotCLo', width=800, height=450)

 

Sample Code

我们有一些你以前见过的模型设置代码。 它暂时不是我们关注的焦点.

[2]

from tensorflow.python.keras.applications import ResNet50
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, Flatten, GlobalAveragePooling2Dnum_classes = 2
resnet_weights_path = '../input/resnet50/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5'my_new_model = Sequential()
my_new_model.add(ResNet50(include_top=False, pooling='avg', weights=resnet_weights_path))
my_new_model.add(Dense(num_classes, activation='softmax'))# Say not to train first layer (ResNet) model. It is already trained
my_new_model.layers[0].trainable = Falsemy_new_model.compile(optimizer='sgd', loss='categorical_crossentropy', metrics=['accuracy'])

Fitting a Model With Data Augmentation

[3]

from tensorflow.python.keras.applications.resnet50 import preprocess_input
from tensorflow.python.keras.preprocessing.image import ImageDataGeneratorimage_size = 224data_generator_with_aug = ImageDataGenerator(preprocessing_function=preprocess_input,horizontal_flip=True,width_shift_range = 0.2,height_shift_range = 0.2)train_generator = data_generator_with_aug.flow_from_directory('../input/urban-and-rural-photos/rural_and_urban_photos/train',target_size=(image_size, image_size),batch_size=24,class_mode='categorical')data_generator_no_aug = ImageDataGenerator(preprocessing_function=preprocess_input)
validation_generator = data_generator_no_aug.flow_from_directory('../input/urban-and-rural-photos/rural_and_urban_photos/val',target_size=(image_size, image_size),class_mode='categorical')my_new_model.fit_generator(train_generator,steps_per_epoch=3,epochs=2,validation_data=validation_generator,validation_steps=1)
Found 72 images belonging to 2 classes.
Found 20 images belonging to 2 classes.
Epoch 1/2
3/3 [==============================] - 32s 11s/step - loss: 0.7974 - acc: 0.5556 - val_loss: 0.9505 - val_acc: 0.7000
Epoch 2/2
3/3 [==============================] - 28s 9s/step - loss: 0.5379 - acc: 0.7639 - val_loss: 0.4675 - val_acc: 0.8000<tensorflow.python.keras._impl.keras.callbacks.History at 0x7f8ce4375f60>

 

Exercise:Data Augmentation

Exercise Introduction

我们将返回您在上一个练习中处理的自动旋转问题。
我们还提供了您已经使用过的大部分代码。 复制这篇笔记并采取数据增加步骤(下面的步骤2)。

 

1) Specify and Compile the Model

这与您之前使用的代码的工作方式相同。 所以你在这里收到了它的完整版本。 运行此单元格以指定和编译模型

【4】

from tensorflow.python.keras.applications import ResNet50
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, Flatten, GlobalAveragePooling2Dnum_classes = 2
resnet_weights_path = '../input/resnet50/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5'my_new_model = Sequential()
my_new_model.add(ResNet50(include_top=False, pooling='avg', weights=resnet_weights_path))
my_new_model.add(Dense(num_classes, activation='softmax'))my_new_model.layers[0].trainable = Falsemy_new_model.compile(optimizer='sgd', loss='categorical_crossentropy', metrics=['accuracy'])

2) Fit the Model Using Data Augmentation

填写空白,并取消注释这些代码行。 在这样做之后,您可以运行此单元格,您应该获得一个达到约90%准确度的模型。 通过使用数据扩充,您可以将错误率降低一半。

【5】

from tensorflow.python.keras.applications.resnet50 import preprocess_input
from tensorflow.python.keras.preprocessing.image import ImageDataGeneratorimage_size = 224# Specify the values for all arguments to data_generator_with_aug. Then uncomment those lines
#data_generator_with_aug = ImageDataGenerator(preprocessing_function=preprocess_input
#                                              horizontal_flip = _____,
#                                              width_shift_range = ____,
#                                              height_shift_range = ____)# data_generator_no_aug = ImageDataGenerator(preprocessing_function=preprocess_input)# Specify which type of ImageDataGenerator above is to load in training data
#train_generator = ____.flow_from_directory(
#        directory = '../input/dogs-gone-sideways/images/train',
#        target_size=(image_size, image_size),
#        batch_size=12,
#        class_mode='categorical')# Specify which type of ImageDataGenerator above is to load in validation data
#validation_generator = ____.flow_from_directory(
#        directory = '../input/dogs-gone-sideways/images/val',
#        target_size=(image_size, image_size),
#        class_mode='categorical')#my_new_model.fit_generator(
#        ____, # specify where model gets training data
#        epochs = 3,
#        steps_per_epoch=19,
#        validation_data=____) # specify where model gets validation data

 

Keep Going

您已准备好深入了解深度学习。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440260.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

朴素贝叶斯算法注意事项(有待完善)

1.朴素贝叶斯算法的优缺点总结&#xff1a; 优点&#xff1a; 朴素贝叶斯模型发源于古典数学理论&#xff0c;有稳定的分类效率&#xff1b;分类速度快&#xff0c;准确度高&#xff1b;对缺失数据不太敏感&#xff0c;算法简单&#xff0c;常用于文本分类&#xff08;如新闻…

网络编程懒人入门(三):快速理解TCP协议一篇就够

转自即时通讯网&#xff1a;http://www.52im.net/ 原作者&#xff1a;阮一峰(ruanyifeng.com&#xff09;&#xff0c;本文由即时通讯网重新整理发布&#xff0c;感谢原作者的无私分享。 1、前言 本系列文章的前两篇《网络编程懒人入门(一)&#xff1a;快速理解网络通信协议…

【数据库实验课堂】实验三:管理SQL Server表数据

以课本指定的数据库为例&#xff0c;并依据数据表的结构创建相对应的数据表&#xff08;student、course、sc&#xff09;&#xff0c;请分别使用Management Stuio界面方式及T-SQL 语句实现进行以下操作&#xff1a; 向各个数据表中插入如下记录&#xff1a; 学生信息表&#…

分类问题的模型评估指标总结

在分类任务下&#xff0c;预测结果(Predicted Condition)与正确标记(True Condition)之间存在四中不同的组合&#xff0c;构成混淆矩阵(可适用于多分类)&#xff0c;通常有这几种主要模型评估指标&#xff1a;精确率(查的准)、召回率(查的全对正样本的区分能力)、F1值(反映模型…

6. A Deeper Understanding of Deep Learning

Intro 这是深度学习第6课。 在本课程结束时&#xff0c;您将了解随机梯度下降和反向传播如何用在深度学习模型中设置权重。 这些主题很复杂&#xff0c;但许多专家认为它们是深度学习中最重要的思想。 Lesson [1] from IPython.display import YouTubeVideo YouTubeVideo(…

JetBrains - IDEA 常用快捷键汇总

【常规】 CtrlShift Enter&#xff0c;语句完成“&#xff01;”&#xff0c;否定完成&#xff0c;输入表达式时按 “&#xff01;”键CtrlE&#xff0c;最近的文件CtrlShiftE&#xff0c;最近更改的文件ShiftClick&#xff0c;可以关闭文件Ctrl[ OR ]&#xff0c;可以跑到大…

nltk安装punkt等语料库时报SSL错误完美解决方案及离线安装方法

nltk是NLP领域中一个比较通用的国际分词工具&#xff0c;但是使用时往往依赖语料库数据包&#xff0c;需要安装到本地&#xff0c;以下介绍在线安装和离线安装两种方式&#xff1a; &#xff08;ps&#xff1a;对NLP感兴趣的朋友可以相互学习&#xff0c;我的微信号&#xff1…

7. Deep Learning From Scratch

Intro 这是深度学习第7课。 到目前为止&#xff0c;您构建的模型依赖于预先训练的模型。 但它们不是许多用例的理想解决方案。 在本课程中&#xff0c;您将学习如何构建全新的模型。 Lesson [1] from IPython.display import YouTubeVideo YouTubeVideo(YbNE3zhtsoo, widt…

【POJ - 3126】Prime Path(bfs)

题干&#xff1a; 给你两个四位的素数a&#xff0c;b。 a可以改变某一位上的数字变成c&#xff0c;但只有当c也是四位的素数时才能进行这种改变。 请你计算a最少经过多少次上述变换才能变成b。 例如&#xff1a;1033 -> 8179 1033 1733 3733 3739 3779 8779 8179 最…

最实用的Git命令总结:新建本地分支、远程分支、关联和取消关联分支、清除本地和远程分支、合并分支、版本还原、tag命令、中文乱码解决方案、如何fork一个分支和修改后发起合并请求

1.常用命令git、tag整理 1、新建分支本地分支 git branch <branch-name>远程分支 git push origin <branch-name>:<new-branch-name> 2、删除分支本地分支 git branch -d <branch-name> 或 git branch -D <branch-name>远程分支 git push o…

8. Dropout and Strides For Larger Models

Intro 这是深度学习第8课。 本科结束后&#xff0c;你将会理解并知道如何使用&#xff1a; Stride lengths来快速建立模型并减少内存消耗&#xff1b;Dropout 来对抗过拟合&#xff1b; 这两个技术在大型模型中很有用。 Lesson [1] from IPython.display import YouTubeV…

【POJ - 2255】Tree Recovery (给定树的先序中序,输出后序)

题干&#xff1a; Input The input will contain one or more test cases. Each test case consists of one line containing two strings preord and inord, representing the preorder traversal and inorder traversal of a binary tree. Both strings consist of unique…

Java基础部分快速复习(以前复习的时候放在自己的新浪博客上)

工作后Java基本没有用到&#xff0c;有时候自己也会把基础过一遍&#xff0c;下面的链接是以前重温的时候整理的Java基础最核心部分的知识点和代码示例放在自己的新浪博客上&#xff0c;如果以后有需要&#xff0c;直接从这里进入&#xff0c;可以快速复习&#xff0c;节省时间…

0.Overview——Deep Learning

本文为Kaggle Learn的Deep Learning课程的中文翻译。原链接为&#xff1a;https://www.kaggle.com/learn/deep-learning 1. Intro to Deep Learning and Computer Vision A quick overview of how models work on images 2. Building Models from Convolutions Scale up fr…

SQL基础用法总结(以前复习的时候放在自己的新浪博客上)

工作后主要做移动端和前端这一块&#xff0c;后端的知识都是靠自己学习积累的&#xff0c;下面的链接是以前重温的时候整理的SQL基础最核心部分的知识点和代码示例放在自己的新浪博客上&#xff0c;如果以后有需要&#xff0c;直接从这里进入&#xff0c;可以快速复习&#xff…

【HDU - 4786 】Fibonacci Tree (最小生成树变形,上下界贪心,tricks)

题干&#xff1a; Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do some research on Spanning Tree. So Coach Pang decides to solve the following problem:   Consider a bidirectional graph G with N vertices and M edges. All edg…

网络编程懒人入门(四):快速理解TCP和UDP的差异

转自即时通讯网&#xff1a;http://www.52im.net/ 原作者&#xff1a;MeloDev&#xff0c;本文由即时通讯网重新修订发布&#xff0c;感谢原作者的无私分享。 1、前言 对于即时通讯开发者新手来说&#xff0c;在开始着手编写IM或消息推送系统的代码前&#xff0c;最头疼的问…

【HDU - 5455】Fang Fang(水题,有坑)

题干&#xff1a; Fang Fang says she wants to be remembered. I promise her. We define the sequence FF of strings. F0 ‘‘f",F0 ‘‘f", F1 ‘‘ff",F1 ‘‘ff", F2 ‘‘cff",F2 ‘‘cff", Fn Fn−1 ‘‘f", for n &g…

npm安装与卸载和cordova及ionic项目打包调试等相关命令总结归纳

一、安装和卸载node和npm的命令 1、Mac系统彻底卸载npmsudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}2、因网络问题导致包安装失败的安全解决方法cd到对应项目之下&#xff0c;如果有权限问题前加sudorm -rf node_modules/npm c…

Apollo自动驾驶入门课程第⑤讲 — 感知(下)

目录 1. 卷积神经网络 2. 检测与分类 3. 跟踪 4. 分割 5. Apollo感知 6. 传感器数据比较 7. 感知融合策略 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a; 阿波君 Apollo开发者社区 8月29日 上一篇文章中&#xff0c;我们发布了无人驾驶技术的 感知篇…