建设网站中存在的问题,辽宁网站seo,做家居网站设计,做简历有什么网站Intro
这是深度学习第5课
在本课程结束时#xff0c;您将能够使用数据增强。 这个技巧让你看起来拥有的数据远远超过实际拥有的数据#xff0c;从而产生更好的模型。 Lesson
[1]
from IPython.display import YouTubeVideo
YouTubeVideo(ypt_BAotCLo, width800, height45…Intro
这是深度学习第5课
在本课程结束时您将能够使用数据增强。 这个技巧让你看起来拥有的数据远远超过实际拥有的数据从而产生更好的模型。 Lesson
[1]
from IPython.display import YouTubeVideo
YouTubeVideo(ypt_BAotCLo, width800, height450) 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.h5my_new_model Sequential()
my_new_model.add(ResNet50(include_topFalse, poolingavg, weightsresnet_weights_path))
my_new_model.add(Dense(num_classes, activationsoftmax))# Say not to train first layer (ResNet) model. It is already trained
my_new_model.layers[0].trainable Falsemy_new_model.compile(optimizersgd, losscategorical_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_functionpreprocess_input,horizontal_flipTrue,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_size24,class_modecategorical)data_generator_no_aug ImageDataGenerator(preprocessing_functionpreprocess_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_modecategorical)my_new_model.fit_generator(train_generator,steps_per_epoch3,epochs2,validation_datavalidation_generator,validation_steps1)
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.8000tensorflow.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.h5my_new_model Sequential()
my_new_model.add(ResNet50(include_topFalse, poolingavg, weightsresnet_weights_path))
my_new_model.add(Dense(num_classes, activationsoftmax))my_new_model.layers[0].trainable Falsemy_new_model.compile(optimizersgd, losscategorical_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_functionpreprocess_input
# horizontal_flip _____,
# width_shift_range ____,
# height_shift_range ____)# data_generator_no_aug ImageDataGenerator(preprocessing_functionpreprocess_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_size12,
# class_modecategorical)# 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_modecategorical)#my_new_model.fit_generator(
# ____, # specify where model gets training data
# epochs 3,
# steps_per_epoch19,
# validation_data____) # specify where model gets validation data Keep Going
您已准备好深入了解深度学习。