Python实现单神经元分类图片的训练
1、加载包和数据
- numpy is the fundamental package for scientific computing with Python.
- h5py is a common package to interact with a dataset that is stored on an H5 file.
- matplotlib is a famous library to plot graphs in Python.
- PIL and scipy are used here to test your model with your own picture at the end
__author__ = 'Qian Chenglong' import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy
from scipy import ndimage
from lr_utils import load_dataset #load data
train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()
2、处理数据
1)看一下数据的形状
#get she shape of thed data
print(train_set_x_orig.shape)
print(train_set_y.shape)
print(test_set_x_orig.shape)
print(test_set_y.shape)
print(classes.shape)
2)获取训练数据个数和测试数据个数,图片是64*64*3的格式
#the number of data,train number is 209 test number is50
m_train = train_set_x_orig.shape[0]
m_test = test_set_x_orig.shape[0] #the picture's row * col =64*64 channel=3
num_px = train_set_x_orig.shape[1]
3)重构数据形状
A trick when you want to flatten a matrix X of shape (a,b,c,d) to a matrix X_flatten of shape (b∗c∗d, a) is to use:
X_flatten = X.reshape(X.shape[0], -1).T # X.T is the transpose of X
train_set_x_flatten = train_set_x_orig.reshape(train_set_x_orig.shape[0], -1).T
test_set_x_flatten = test_set_x_orig.reshape(test_set_x_orig.shape[0], -1).T
4)标准化(归一化)处理数据,因为图片的数据都是0~255的所以我们直接/255
# standardize our dataset.
train_set_x = train_set_x_flatten/255.
test_set_x = test_set_x_flatten/255.
5)定义要使用的函数
sigmoid函数在这里被称为激活函数。
Python实现单神经元分类图片的训练的更多相关文章
- Python实现鸢尾花数据集分类问题——基于skearn的NaiveBayes
Python实现鸢尾花数据集分类问题——基于skearn的NaiveBayes 代码如下: # !/usr/bin/env python # encoding: utf-8 __author__ = ...
- Python实现鸢尾花数据集分类问题——基于skearn的LogisticRegression
Python实现鸢尾花数据集分类问题——基于skearn的LogisticRegression 一. 逻辑回归 逻辑回归(Logistic Regression)是用于处理因变量为分类变量的回归问题, ...
- Python实现鸢尾花数据集分类问题——基于skearn的SVM
Python实现鸢尾花数据集分类问题——基于skearn的SVM 代码如下: # !/usr/bin/env python # encoding: utf-8 __author__ = 'Xiaoli ...
- caffe学习--使用caffe中的imagenet对自己的图片进行分类训练(超级详细版) -----linux
http://blog.csdn.net/u011244794/article/details/51565786 标签: caffeimagenet 2016-06-02 12:57 9385人阅读 ...
- python中学习K-Means和图片压缩
python中学习K-Means和图片压缩 大家在学习python中,经常会使用到K-Means和图片压缩的,我们在此给大家分享一下K-Means和图片压缩的方法和原理,喜欢的朋友收藏一下吧. 通俗的 ...
- 用webdriver模仿浏览器 爬取豆瓣python书单
用webdriver模仿浏览器 爬取豆瓣python书单 其中运用到os 模块 作用是生成文件夹 存储爬取的信息 etree 用于xpath解析内容 详细代码如下 可用我的上一篇博客存取到excel当 ...
- Python爬虫02——贴吧图片爬虫V2.0
Python小爬虫——贴吧图片爬虫V2.0 贴吧图片爬虫进阶:在上次的第一个小爬虫过后,用了几次发现每爬一个帖子,都要自己手动输入帖子链接,WTF这程序简直反人类!不行了不行了得改进改进. 思路: 贴 ...
- PID控制器开发笔记之十三:单神经元PID控制器的实现
神经网络是模拟人脑思维方式的数学模型.神经网络是智能控制的一个重要分支,人们针对控制过程提供了各种实现方式,在本节我们主要讨论一下采用单神经元实现PID控制器的方式. 1.单神经元的基本原理 单神经元 ...
- python 3编写贴吧图片下载软件(超简单)
业余时间初学者作品,大佬勿喷,代码都很简单. py文件打包成exe教程:python3.7 打包成exe程序, 本程序体验下载地址:python编译的贴吧图片下载工具 先上效果图 启动后是这样的: 按 ...
随机推荐
- C++ 俄罗斯方块
#include <iostream> #include <string.h> #include <stdlib.h> #include <time.h> ...
- MYSQL - database 以及 table 的增删改查
MYSQL - database 以及 table 的增删改查 MySQL的相关概念介绍 MySQL 为关系型数据库(Relational Database Management System), 这 ...
- day15 python-03 列表,元组,字典
Python之路,Day3 = Python基础3 注: extend: 拼接 enumerate:打印序号,返回两个值 模块的简单使用 sys模块 #!/usr/bin/env python #这句 ...
- java反射快速入门
笔记记在了掘金,发现掘金的markdown编辑器比博客园样式要好看不少 https://juejin.im/post/5d4e575af265da03e4674e9f
- 二分图建图,并查集求联通——二维等价性传递 cf1012B好题!
/* 模拟二分图:每个点作为一条边,连接的是一列和一行(抽象成一个点,列在左,行在右) 由题意得 a-b相连,a-c相连,b-d相连,那么d-c就不用再相连了 等价于把二分图变成联通的需要再加多少边 ...
- NOI2014
听说14,15年的题是最简单的,然后除了提答以外的不那么水的题都是以前讲过.做过的,都比较好想到,但是我实现起来却有各种Bug,也完全不能在5h里AC...太弱了 [NOI2014]起床困难综合症 纯 ...
- IDEA被删除的模块在编译时会再次出现
工程根目录下.idea文件->compiler.xml,删除多余的model,workspace.xml->删除带有无用的target标签
- linux安装PyCharm,PyCharm常用快捷键及调试模式,pycharm里面对文件夹或者文件进行重命名
PyCharm常用快捷键及调试模式 2017年10月18日 23:13:43 菜鸟之神 阅读数:5835 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...
- floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253
The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...
- NEO4J全文检索架构
NEO4J全文检索架构 一.有大量存量数据(亿级以上)(并长期有增量数据进入) 二.无大量存量数据或者少量存量数据(或全部为增量数据) 三.架构方案选择优先级 以下方案,是根据实践总结的基于NEO4J ...