代码拉取完成,页面将自动刷新
同步操作将从 yuguolong/Glasses-recognition-master 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from keras.models import Model
from keras.applications.mobilenet import MobileNet
from keras.layers import SeparableConv2D,Dropout,Dense,MaxPooling2D,Flatten,GlobalAveragePooling2D,Input
from keras.preprocessing.image import ImageDataGenerator
#model
base_model = MobileNet(alpha=0.25, depth_multiplier=1, dropout=1e-4,weights='imagenet', include_top=False)
base_model.trainable = False
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dropout(0.3)(x)
x = Dense(64,activation='relu')(x)
x = Dropout(0.1)(x)
predictions = Dense(2, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=predictions)
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
#数据读入
train_datagen = ImageDataGenerator(rescale=1./255,
# horizontal_flip=True,
# vertical_flip=True,
# rotation_range=2,
# zoom_range=0.3,
width_shift_range=0.2,
height_shift_range=0.2
)
# 测试集不许动,去均值中心化完了之后不许动
validation_datagen = ImageDataGenerator(rescale=1./255)
train_dir = './train_data/train'
validation_dir = './train_data/test'
# 利用python生成器不断的生成训练样本
train_generator = train_datagen.flow_from_directory(
train_dir,
# 缩放到356*356
target_size=(160, 160),
# 每个批量包含batch_size个样本
batch_size=100,
# 因为是单标签,多分类问题,最后损失函数要用catagorical_crossentropy,所以此处用catagorical
class_mode='categorical')
validation_generator = validation_datagen.flow_from_directory(
validation_dir,
target_size=(160, 160),
batch_size=14,
class_mode='categorical')
model.fit_generator(
train_generator,
class_weight= [1,1.1],
steps_per_epoch=8,
epochs=5,
validation_data=validation_generator,
validation_steps=3,
verbose=1)
model.save('./MobileNet.h5')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。