卷积神经网络的keras实现

深度残差网络的代码实现

深度残差网络是中微软kaiming he等提出的,在ILSVRC 2015中的classification,detection,localization任务取得了冠军,且在COCO比赛上也夺冠【论文】。在这里对深度残差网络使用keras实现,这里使用的数据集是notmnist,字母A-J,十个字母的识别。(数据集小,渣渣笔记本上运行)

1. 读取数据

import os
import numpy as np
import cv2
import matplotlib.pyplot as plt
import tqdm
train_path='../datasets/notmnist/notMNIST_large/'
test_path='../datasets/notmnist/notMNIST_small/'
img_size=28
num_channels=3

# 读取文件夹图像
def read_letters(folder, size=None):
    image_names=os.listdir(folder,)
    images=[]
    for index, img_name in enumerate(image_names):
        if size and index>size-1: break
        image=cv2.imread(folder+img_name)
        if not image is None: 
            images.append(image)
    return np.array(images)

A=read_letters(train_path+'A/', 100)
print('complete!')
plt.imshow(A[66])
plt.show()
complete!

png

def concate(x, x_):
    if not x is None: 
        x=np.concatenate([x, x_], axis=0)
    else: x=x_
    return x

def get_data(train_size=None, test_size=None):
    letters=['A', 'B','C','D','E','F','G','H','I','J']
    x_train=y_train=x_test=y_test=None
    for index, letter in tqdm.tqdm(enumerate(letters)):
        x_=read_letters(train_path+letter+'/', train_size)
        x_train=concate(x_train, x_)
        y_=np.ndarray([x_.shape[0]], dtype=np.uint8)
        y_[:]=index
        y_train=concate(y_train, y_) 
        x_=read_letters(test_path+letter+&#
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值