TensorFlow Keras ImageDataGenerator VGG16 Bottleneck

猫狗识别  

#%%

from keras.applications.vgg16 import VGG16
import numpy as np
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential, load_model
from keras.layers import Dropout, Flatten, Dense
from keras.optimizers import Adam

#%%

# 载入VGG网络,不包括全连接层
model = VGG16(weights='imagenet', include_top=False)

#%%

model.summary()

#%%

# 对图片进行随机处理,以扩大数据集
datagen = ImageDataGenerator(
    # 随机旋转角度
    rotation_range=40,
    # 随机水平平移
    width_shift_range=0.2,
    # 随机竖直平移
    height_shift_range=0.2,
    # 数值归一化
    rescale=1. / 255,
    # 随机裁剪
    shear_range=0.2,
    # 随机放大
    zoom_range=0.2,
    # 水平翻转
    horizontal_flip=True,
    # 填充方式
    fill_mode='nearest'
)

#%%

batch_size = 32
# 训练集生成器
train_generator = datagen.flow_from_directory(
    # 训练集路径
    'image/train',
    # 设置生成的图片大小
    target_size=(150, 150),
  

你可能感兴趣的:(Python,tensorflow,keras,深度学习)