VGG16(学习)

ysz12316 ysz12316 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from keras.utils import to_categorical
from keras.datasets import fashion_mnist
from keras.layers import Input, Conv2D, MaxPooling2D, Dense, Flatten, Dropout
from keras.optimizers import Adam
from keras.models import Model
def vgg16(input_shape):
input_tensor=Input(shape=input_shape)
x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv1')(input_tensor)
x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv2')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='block1_pool')(x)
print(x.shape)
# Block 2
x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv1')(x)
x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv2')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x)
print(x.shape)
# Block 3
x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv1')(x)
x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv2')(x)
x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv3')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='block3_pool')(x)
print(x.shape)
# Block 4
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv1')(x)
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv2')(x)
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv3')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='block4_pool')(x)
print(x.shape)
# # Block 5
# x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv1')(x)
# x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv2')(x)
# x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv3')(x)
# x = MaxPooling2D((2, 2), strides=(2, 2), name='block4_pool')(x)
# print(x.shape)

# Classification block
x = Flatten(name='flatten')(x)
x = Dense(4096, activation='relu', name='fc1')(x)
x = Dense(4096, activation='relu', name='fc2')(x)
x = Dropout(0.5)(x)
x = Dense(10, activation='softmax', name='predictions')(x)
model = Model(inputs=input_tensor, outputs=x, name='VGG16')
return model

model = vgg16(input_shape = (28, 28, 1))

model.compile(optimizer=Adam(lr=0.001), loss='categorical_crossentropy', metrics=['accuracy'])

(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
x_train = x_train/255
x_test = x_test/255
x_train, x_validate, y_train, y_validate = train_test_split(x_train, y_train, test_size=0.2, random_state=0)
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
x_validate = x_validate.reshape(x_validate.shape[0], 28, 28, 1)
x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)


print('x_train shape: {}'.format(x_train.shape))
print('x_test shape: {}'.format(x_test.shape))
print('x_validate shape: {}'.format(x_validate.shape))
print ("y_train shape: " + str(y_train.shape))
print ("y_test shape: " + str(y_test.shape))
model.fit(x_train, y_train, epochs = 10, batch_size = 512)

preds = model.evaluate(x_test, y_test)
print ("Loss = " + str(preds[0]))
print ("Test Accuracy = " + str(preds[1]))
...全文

相关推荐

VGG16学习

VGG16学习

crazed1987

【深度学习】全面理解VGG16模型

全面理解VGG16模型VGG16的结构层次介绍结构图VGG16模型所需要的内存容量介绍卷积中的基本概念1.从input到conv1:2.从conv1到conv2之间的过渡:3.conv2到conv3:4.进入conv3:5.从conv3到conv4之间的过渡:6.最后到三层全连接FC层结论 VGG16的结构层次 vgg16总共有16层,13个卷积层和3个全连接层,第一次经过64个卷积核的两次卷积后...

Florrie Zhu

基于vgg16进行迁移学习服装分类

服装数据集,超过5000张图片,20个不同类别。创建教程或课程(免费或付费)写一本书Kaggle竞赛(作为外部数据集)在任何公司培训内部模型image - 图像的 ID(使用它从images/.jpg加载图像)sender_id - 贡献图像的人的 IDlabel - 图像的类kids - 标记为“true”,说明它是孩子们的衣服结构简洁。

海洋 之心

VGG16迁移学习实现

VGG16迁移学习实现 本文讨论迁移学习,它是一个非常强大的深度学习技术,在不同领域有很多应用。动机很简单,可以打个比方来解释。假设想学习一种新的语言,比如西班牙语,那么从已经掌握的另一种语言(比如英语)学起,可能是有用的。 按照这种思路,计算机视觉研究人员通常使用预训练 CNN 来生成新任务的表示,其中数据集可能不够大,无法从头开始训练整个 CNN。另一个常见的策略是采用在 ImageNet 上预训练好的网络,然后通过微调整个网络来适应新任务。 这里提出的例子受启于 Francois Chollet 写的

wujianming_110117

深度学习VGG16 网络实例

···此资源是基于猫狗二分类的VGG16网络实例呃,由tensorflow实现,需要借鉴学习的自取。

海狸小生
评论 1
收藏 已收藏
分享
返回顶部
ysz12316
版主专区 514 成员 265 内容