• 大小: 15KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: Matlab
  • 标签: matlab  cnn  

资源简介

内含cnn的matlab程序,简单易懂,不到百行,混科研搞数据必备良代码。超低价甩卖。

资源截图

代码片段和文件信息


# -*- coding: utf-8 -*-
“““
Created on Thu Aug 27 11:27:34 2015

@author: lab-liu.longpo
“““


from __future__ import absolute_import
from __future__ import print_function
from keras.models import Sequential
from keras.layers.core import Dense Dropout Activation Flatten
from keras.layers.convolutional import Convolution2D MaxPooling2D
from keras.optimizers import SGD Adadelta Adagrad
from keras.utils import np_utils generic_utils

import matplotlib.pyplot as plt
import numpy as np
import scipy.io as sio

d = sio.loadmat(‘data.mat‘)
data = d[‘d‘]
label = d[‘l‘]
data = np.reshape(data(5000033232))
label = np_utils.to_categorical(label 10)

print (‘finish loading data‘)

model = Sequential()

model.add(Convolution2D(32 3 5 5 border_mode=‘valid‘)) 
model.add(Activation(‘relu‘))
#model.add(MaxPooling2D(poolsize=(2 2)))
model.add(Dropout(0.25))

model.add(Convolution2D(32 32 5 5 border_mode=‘valid‘)) 
model.add(Activation(‘relu‘))
model.add(MaxPooling2D(poolsize=(2 2)))
model.add(Dropout(0.25))

model.add(Convolution2D(64 32 3 3 border_mode=‘valid‘)) 
model.add(Activation(‘relu‘))
model.add(MaxPooling2D(poolsize=(2 2)))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(64*5*5 512 init=‘normal‘))
model.add(Activation(‘tanh‘))

model.add(Dense(512 10 init=‘normal‘))
model.add(Activation(‘softmax‘))

sgd = SGD(l2=0.001lr=0.0065 decay=1e-6 momentum=0.9 nesterov=True)
model.compile(loss=‘categorical_crossentropy‘ optimizer=sgdclass_mode=“categorical“)

#checkpointer = ModelCheckpoint(filepath=“weight.hdf5“verbose=1save_best_only=True)
#model.fit(data label batch_size=100nb_epoch=10shuffle=Trueverbose=1show_accuracy=Truevalidation_split=0.2callbacks=[checkpointer])
result = model.fit(data label batch_size=50nb_epoch=35shuffle=Trueverbose=1show_accuracy=Truevalidation_split=0.2)
#model.save_weights(weightsaccuracy=False)

# plot the result

plt.figure
plt.plot(result.epochresult.history[‘acc‘]label=“acc“)
plt.plot(result.epochresult.history[‘val_acc‘]label=“val_acc“)
plt.scatter(result.epochresult.history[‘acc‘]marker=‘*‘)
plt.scatter(result.epochresult.history[‘val_acc‘])
plt.legend(loc=‘under right‘)
plt.show()

plt.figure
plt.plot(result.epochresult.history[‘loss‘]label=“loss“)
plt.plot(result.epochresult.history[‘val_loss‘]label=“val_loss“)
plt.scatter(result.epochresult.history[‘loss‘]marker=‘*‘)
plt.scatter(result.epochresult.history[‘val_loss‘]marker=‘*‘)
plt.legend(loc=‘upper right‘)
plt.show()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2517  2016-05-02 15:13  DeepLearning\CNN_cifar-10\cifar.py

     文件       2724  2016-05-02 15:13  DeepLearning\CNN_mnist\cnn.py

     文件        492  2016-05-02 15:13  DeepLearning\CNN_mnist\data.py

     文件        608  2016-05-02 15:13  DeepLearning\CNN_mnist\trainCNN.py

     文件       2647  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\display_network.m

     文件       1305  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\feedForwardAutoencoder.m

     文件        622  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\initializeParameters.m

     文件        811  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\loadMNISTImages.m

     文件        516  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\loadMNISTLabels.m

     文件       1589  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\softmaxCost.m

     文件        743  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\softmaxPredict.m

     文件       1891  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\softmaxTrain.m

     文件       4335  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\sparseAutoencoderCost.m

     文件       5243  2016-05-02 15:13  DeepLearning\UFLDL\stl_exercise\stlExercise.m

     文件       2018  2016-05-02 15:13  DeepLearning\UFLDL\Vectorization_sparseae_exercise\checkNumericalGradient.m

     文件       1228  2016-05-02 15:13  DeepLearning\UFLDL\Vectorization_sparseae_exercise\computeNumericalGradient.m

     文件       2647  2016-05-02 15:13  DeepLearning\UFLDL\Vectorization_sparseae_exercise\display_network.m

     文件        622  2016-05-02 15:13  DeepLearning\UFLDL\Vectorization_sparseae_exercise\initializeParameters.m

     目录          0  2018-06-29 20:01  DeepLearning\UFLDL\stl_exercise

     目录          0  2018-06-29 20:01  DeepLearning\UFLDL\Vectorization_sparseae_exercise

     目录          0  2018-06-29 20:01  DeepLearning\CNN_cifar-10

     目录          0  2018-06-29 20:01  DeepLearning\CNN_mnist

     目录          0  2018-06-29 20:01  DeepLearning\UFLDL

     目录          0  2018-06-29 20:01  DeepLearning

----------- ---------  ---------- -----  ----

                32558                    24


评论

共有 条评论