之前弄过caffe,但是caffe用来做自己的数据太矫情和麻烦了,据说Keras简单点。现在按http://blog.csdn.net/niuwei22007/article/details/49045909配置,在自习室的台式机上,根据http://blog.csdn.net/niuwei22007/article/details/47684673装了VS2015 然后装Anaconda装的时候好慢啊。。。。这样就装好MinGw了。接着就是theano输入theano.test()后报了点错

http://blog.csdn.net/niuwei22007/article/details/47684673说可以忽略 我就忽略了。

这样就OK了

然后看了下学校自习室的电脑 竟然不是NVIDIA的  装不了CUDA 于是又只能在公司的电脑上重来一次了。公司电脑上是VS2013 我根据自己的显卡型号装的CUDA7.5可是竟然提示错了??于是我又把原来的CUDA 卸载了重装一次。。。心是崩溃的。。。但重装后还是这样  于是跳过这一步 按照http://blog.csdn.net/m624197265/article/details/45700619运行particle.sln的实例  因为我没找到.exe  所以运行了这个 目录是在C:\Program Files\NVIDIA Corporation\Installer2\CUDASamples_7.5.{F073AFAC-37AB-4C61-85C7-302041E69D36}\5_Simulations\particles下   和作者说的目录不一样  我运行后  证明是可以运行的  那应该就是CUDA可以了吧

然后我没有继续按照这个博客手动配置环境变量 因为之前已经有CUDA-PATH了 就直接进行第7步:然后

可是右下角出现的是use cpu  不是gpu!!!!!!!!!!!!!!我的心是拒绝看到的。。。。。。天哪心里一万匹马奔腾而过。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

重来吧按照http://blog.csdn.net/xuhang0910/article/details/47906949这个人的重新安装!

CUDA7.5傻瓜式安装 后nvcc和-V之间有空格!!!!之前我输入的都是nvcc-V难怪错了 注意空格!按照他的一直安装到这步 开始出错了。。。??

我又尝试了很多人写的安装教程 然而。。。又搞了一天 体会了哀莫大于心死的感觉。。。把之前的所有卸载 添加的环境变量也删除。。。电脑干净。从头配置  按照http://blog.csdn.net/hjimce/article/details/46654229这个人的:

一路配置到一直下去。。。可是结果呢还是CPU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!我已经疯了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。import theano检查下

出来的是这个提示!!!!我已经疯了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

昨天是我第一次加班 加班到公司只剩我一人到晚上八点。。。一转身 外面天都黑了。。。就为了这个东西。。。又饿又累又困又烦躁。。。连我自己都被自己感动了。。。

现在是北京时间我终于装成功了。。。我要祭奠这个伟大的时刻  括号里的信息可以不管  import theano终于出来显卡型号了   激动得我手都颤抖了。。。连忙马上打开 spyder那个例子看 终于出来gpu了!!!!!!!!!!!!!!!!!!!!!!!!!!看现在的时间比之前cpu的时间少了N多有没有!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!我要去拿卫生纸擦眼泪了,,,激动到我痛哭流涕!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

但这是我自己瞎弄的  我也不知道自己刚刚具体改了什么使得它成功了   我只能说我参考了http://www.cnblogs.com/zhang-pengcheng/p/4553672.html设置这个环境变量  但加代码不知道在哪里加  所以我没加  还有http://blog.csdn.net/hjimce/article/details/46654229我按照他的运行到第4步时候  我没在dos下装VCForPython.msi 因为老是不行  所以我是自己手动装的  而且把stdint.h放在你说的目录下 但我的C:\Program Files (x86)\Common Files\Microsoft目录下没有Visual C++ for Python\9.0\ 我只在C盘找到:C:\用户\admin\AppData\Local\Pragrams\Common\Microsoft\Visual C++ for Python\9.0\include然后我就将stdint.h放在这里了。。。然后关机重启  它就成功了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

在此,给Win7+theano+CUDA+VS的苦行僧一个忠告:

每次设置完环境变量记得重启

多找几个教程试  也许像我一样在快疯了时 莫名其妙就成功了

不要轻易放弃 哪怕你已经觉得自己要挂了  哪怕搞了N天快崩溃了

我最终有很大一部分是按照http://blog.csdn.net/hjimce/article/details/46654229他的来配置的 跳过了dos下装VCForPython 自己手动装  当然还结合了http://www.cnblogs.com/zhang-pengcheng/p/4553672.html这个人设置环境变量的这里

不说了  去擦眼泪。。。血泪史啊。。。

最后就是Keras的安装了  只要上面正确了这个就很简单了  直接在cmd下  输入pip install keras 就行了

接下来按照http://blog.csdn.net/zhoubl668/article/details/45559955测试手写数字mnist

把准确率显示出来:

看 最后一次迭代后 准确率97.56%  。。。。。。。。。。。。。。。。

至此 所有已经安装完毕。我还要去哭一会儿。。。。。。。。为了庆祝 决定给自己买一只心水很久的口红。。。

今天又星期四了,马上又周末了,好happy。用Keras下的CNN实现一个二分类:

参考资料:

http://www.360doc.com/content/16/0714/09/1317564_575383829.shtml  介绍了Keras:Sequential模型下的一些方法 参数含义等

http://keras-cn.readthedocs.io/en/latest/blog/image_classification_using_very_little_data/    Keras中文文档介绍

http://keras-cn.readthedocs.io/en/latest/blog/image_classification_using_very_little_data/
http://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html
http://www.360doc.com/content/16/0714/09/1317564_575383829.shtml
http://backnode.github.io/tag/cnn.html
http://blog.csdn.net/tina_ttl/article/details/51034821
http://blog.csdn.net/eagelangel/article/details/50759993
http://blog.csdn.net/hjimce/article/details/49095199
http://blog.csdn.net/u012162613/article/details/45397033

http://dataunion.org/16787.html

http://blog.csdn.net/niuwei22007/article/details/49207187

http://old.sebug.net/paper/books/scipydoc/numpy_intro.html   Keras的一些对数据的处理

上面都介绍的是与Keras有关的   下面的这些也是我收藏的要看的:

http://blog.csdn.net/zouxy09/article/details/14222605 介绍机器学习的

http://www.csdn.net/article/2015-08-27/2825549    介绍卷积神经网络的

好了,还是看看我参考上面的 来对自己的图片分类  我的两类:kuang:160张  stone:160张  总320张用来做训练   另有valiation文件夹下kuang:32  stone:32张做验证    图片大小不统一   所以都先统一到300X300大小  图片都是3通道的:

"""
Created on Thu Jul 28 14:15:32 2016
http://keras-cn.readthedocs.io/en/latest/blog/image_classification_using_very_little_data/
http://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html
http://www.360doc.com/content/16/0714/09/1317564_575383829.shtml
http://backnode.github.io/tag/cnn.html
http://blog.csdn.net/tina_ttl/article/details/51034821
http://blog.csdn.net/eagelangel/article/details/50759993
http://blog.csdn.net/hjimce/article/details/49095199
http://blog.csdn.net/u012162613/article/details/45397033
@author: admin
"""
from keras.preprocessing.image import ImageDataGenerator,img_to_array, load_img
#from mydata import load_mydata
#import numpy as np
#from keras.utils import np_utils
#import random
#from keras.callbacks import EarlyStopping
#import fit_generator
datagen = ImageDataGenerator(rotation_range=0,width_shift_range=0.2,height_shift_range=0.2,shear_range=0.2,zoom_range=0.2,horizontal_flip=True,fill_mode='nearest')
img = load_img('train/kuang/0.bmp')  # this is a PIL image
x = img_to_array(img)  # this is a Numpy array with shape (3, 150, 150)
x = x.reshape((1,) + x.shape)  # this is a Numpy array with shape (1, 3, 150, 150)
# the .flow() command below generates batches of randomly transformed images
# and saves the results to the `preview/` directory
i = 0
for batch in datagen.flow(x, batch_size=1,save_to_dir='preview', save_prefix='kuang', save_format='bmp'):
    i += 1
    if i > 20:
        break 
###########################################
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
#第一个模型,一个很简单的3层卷积加上ReLU激活函数,再接max-pooling
model = Sequential()
model.add(Convolution2D(32, 3, 3, input_shape=(3,300,300)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(32, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
# the model so far outputs 3D feature maps (height, width, features)
#then两个全连接网络,并以单个神经元和sigmoid激活,二分类使用binary_crossentropy作为损失函数
model.add(Flatten())  # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
##################################################################
#开始准备数据,使用.flow_from_directory()来从我们的图片中直接产生数据和标签
# this is the augmentation configuration we will use for training
train_datagen = ImageDataGenerator(rescale=1./255,shear_range=0.2,zoom_range=0.2,horizontal_flip=True)
# this is the augmentation configuration we will use for testing:
# only rescaling
test_datagen = ImageDataGenerator(rescale=1./255)
# this is a generator that will read pictures found in
# subfolers of 'data/train', and indefinitely generate
# batches of augmented image data
train_generator = train_datagen.flow_from_directory(
        'train',  # this is the target directory
        target_size=(300,300),  # all images will be resized to 150x150
        batch_size=32,
        class_mode='binary')  # since we use binary_crossentropy loss, we need binary labels
# this is a similar generator, for validation data
validation_generator = test_datagen.flow_from_directory(
        'valiation',
        target_size=(300,300),
        batch_size=32,
        class_mode='binary')
##################################################################
#用这个生成器来训练网络
model.compile(loss="binary_crossentropy", optimizer="rmsprop",metrics=["accuracy"])
model.fit_generator(train_generator,samples_per_epoch=320,nb_epoch=5,validation_data=validation_generator,nb_val_samples=64)
#model.save_weights('first_try.h5')  # always save your weights after training or during training
########################################################################################################
#data, label = load_mydata()
#nb_class = 2
#data = np.reshape(data,(384,3,300,300))
#label = np_utils.to_categorical(label, nb_class)
##############################################################

#下面是之前自己想直接从数据fit 但报错  还是用上面的从图片fit  不报错
#model.compile(loss="binary_crossentropy", optimizer="rmsprop",metrics=["accuracy"])
#np.random.seed(1024)
#index = [i for i in range(len(data))]
#random.shuffle(index)
#data = data[index]
#label = label[index]
#(X_train,X_val) = (data[0:300],data[300:])
#(Y_train,Y_val) = (label[0:300],label[300:])
#使用early stopping返回最佳epoch对应的model
#early_stopping = EarlyStopping(monitor='val_loss', patience=1)
#model.fit(X_train, Y_train, batch_size=32,show_accuracy=True,validation_data=(X_val, Y_val),nb_epoch=5,callbacks=[early_stopping])
#cPickle.dump(model,open("./model.pkl","wb"))

结果:

果然是图片太少了吗 还是卷积层等参数不合理   准确率偏低   但目前不管了 二分类的模型是类似这样就行  不报错我就很感谢了   等我把深度学习 神经网络理论了解了再来调整。

又快周末了 欧耶  心情好 放几张我最喜欢的脑残动漫《元气少女缘结神》巴卫和奈奈生:

巴卫变成小孩的样子真是可爱死了。。。

Win7+theano+CUDA+Keras血泪史相关推荐

  1. 64位win7下安装keras的过程

    懒得系统升级,所以到现在仍然在用64位win7. 1,安装Anaconda(强烈建议) Anaconda已经集成了大量第三方包,无需自己一个个手动安装,会省去很多时间和精力,所以强烈建议去下载一个An ...

  2. window10系统基于theano安装Keras

    windows10系统基于theano'0.8.0'安装Keras'1.0.7' 一.电脑系统: windows10 anaconda 二.python需要安装以下模块: 1.Keras versio ...

  3. ubuntu安装Theano+cuda

    ubuntu安装Theano+cuda 由于学习需要用到GPU加速机器学习算法,需要安装theano+cuda. 开源库的一大问题就是:难安装. 为了搞好这个配置,我是前前后后花了3天,重装了3次ub ...

  4. 基于theano的keras安装

     1)首先如果你装的是anaconda的话,只需再装上theano就可以安装keras啦  2)在命令提示符里输入cmd,命令行 pip install keras,一般就ok(网上都这么说),但我的 ...

  5. Python 安装theano tensorflow keras 教程与pip安装失败解决方法

    这几天一直在折腾Python环境的事,好歹折腾出来,做个总结以备用.(注:由于本机没有独立显卡,因此tensorflow 只安装了CPU版) 安装 官方中文文档 Keras安装和配置指南(Window ...

  6. 吐血配置win7+theano+gpu+caffe+matlab+python

    首先感谢大神小鱼人fish.hjimce .double-vane ,本文主要在这三篇博客的基础上,写一下我自己的安装经历.由于我在安装的时候遇到不少问题,所以将三位大神的博客直接复制,在我修改的地方 ...

  7. Win7系统CUDA和cuDNN的安装(选择合适的版本号)

    看了几篇论文,也想着用手头的老设备来学习学习GPU计算,因为学校有matlab正版,虽然python很火,以后再说了. 计算机编程和并行计算,野路子做过一些. 今天以lenovo W530为例说明怎么 ...

  8. win7上安装theano keras深度学习框架

    近期在学习深度学习,需要在本机上安装keras框架,好上手.上网查了一些资料,弄了几天今天终于完全搞好了.本次是使用GPU进行加速,使用cpu处理的请查看之前的随笔keras在win7下环境搭建 本机 ...

  9. python机器学习系列教程——深度学习框架比较TensorFlow、Theano、Caffe、SciKit-learn、Keras

    全栈工程师开发手册 (作者:栾鹏) python教程全解 Theano Theano在深度学习框架中是祖师级的存在.Theano基于Python语言开发的,是一个擅长处理多维数组的库,这一点和nump ...

最新文章

  1. 多线程-synchronized锁
  2. 定时发送服务器运行数据并设置阀值警报方法
  3. 【Android工具】更正视频流媒体播放器测试情况
  4. element table 表格设置max-height 没有出现滚动条,多渲染了一列。
  5. 您必须学习Java 8的函数式编程吗?
  6. 系统起动时加载的过程
  7. libvirt命令行文档
  8. word之八大文本替换技巧
  9. IDEA Unable to import maven project: See logs for details
  10. Android签名证书:jks和keystore
  11. qlabel 添加图标_Qt之添加图标
  12. 最新更新3个QQ空间认证申请入口
  13. html青蛙跳跳游戏,《小青蛙跳跳》小班游戏教案
  14. 小区宽带网络不稳定,宽带断线重连的几种方法(详细)
  15. Source Insight设置黑色背景
  16. 0.前言 与 Eigen库的使用整理
  17. 使用php的GD库拼接图片
  18. IDEA创建applicationContext.xml文件图标不是xml文件图标
  19. 最新广告法规定禁用词汇,不幸被通报,官网小伙伴们记得文案检查下哈
  20. Windows2008系统安全日志分析

热门文章

  1. 程序员,该如何避免成为一个“油腻的怪物”
  2. PHP开发的二级域名分发系统源码 已对接易支付
  3. 中国知识产权保护思辩 华为告三星告出了什么?
  4. 4个良心亲民的微信小程序,要是早点知道就好了!
  5. arm64入栈出栈_使用 ARM64 汇编实现共享栈式协程
  6. 表格数据转换为json格式 python
  7. 2小时完成HTML5拼图小游戏
  8. 惠普打印共享器 hp usb network print adapter 驱动程序软件
  9. 七夕整活?没有难度!手把手教你画个戒指送给ta!
  10. BZOJ 1023: [SHOI2008]cactus仙人掌图