当前位置: 首页 > news >正文

深度学习与python theano

文章目录

  • 前言
    • 1.人工神经网络
    • 2.计算机神经网络
    • 3.反向传播
    • 4.梯度下降-cost 函数
      • 1.一维
      • 2.二维
      • 3.局部最优
      • 4.迁移学习
    • 5. theano-GPU-CPU
  • theano介绍
  • 1.安装
  • 2.基本用法
    • 1.回归
    • 2.分类
  • 3.function用法
  • 4.shared 变量
  • 5.activation function
  • 6.Layer层
  • 7.regression 回归例子
  • 8.classification分类学习
  • 9.过拟合
  • 10.正则化
  • 11.save model
  • 12 总结

前言

本章主要介绍深度学习与python theano。
主要整理来自B站:
1.深度学习框架简介 Theano
2.Theano python 神经网络

1.人工神经网络

2.计算机神经网络

3.反向传播

4.梯度下降-cost 函数

1.一维

2.二维

3.局部最优

大部分时间我们只能求得一个局部最优解

4.迁移学习

5. theano-GPU-CPU

tenforflow鼻祖

theano介绍

1.安装

win10安装theano
设置

ldflags = -lblas

window10安装,这里要说明一点的是python3.8安装theano会出现一些非常奇怪的问题,所以这里选用python3.7.

conda create -n theano_env python=3.7
conda activate theano_env
conda install numpy scipy mkl-service libpython m2w64-toolchain#如果想要安装的快点,可以使用国内的镜像
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple theano

安装后出现了下列问题:
WARNING (theano.tensor.blas): Failed to import scipy.linalg.blas, and Theano flag blas.ldflags is empty. Falling back on slower implementations for dot(matrix, vector), dot(vector, matrix) and dot(vector, vector) (DLL load failed: 找不到指定的模块。)
不过想了一下,自己也只是学习一下而已,慢就慢吧,不用C的

2.基本用法

1.回归

拟合曲线

# View more python tutorials on my Youtube and Youku channel!!!# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
# Youku video tutorial: http://i.youku.com/pythontutorial# 10 - visualize result
"""
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
"""
from __future__ import print_function
import theano
import theano.tensor as T
import numpy as np
import matplotlib.pyplot as pltclass Layer(object):def __init__(self, inputs, in_size, out_size, activation_function=None):self.W = theano.shared(np.random.normal(0, 1, (in_size, out_size)))self.b = theano.shared(np.zeros((out_size, )) + 0.1)self.Wx_plus_b = T.dot(inputs, self.W) + self.bself.activation_function = activation_functionif activation_function is None:self.outputs = self.Wx_plus_belse:self.outputs = self.activation_function(self.Wx_plus_b)# Make up some fake data
x_data = np.linspace(-1, 1, 300)[:, np.newaxis]
noise = np.random.normal(0, 0.05, x_data.shape)
y_data = np.square(x_data) - 0.5 + noise        # y = x^2 - 0.5# show the fake data
plt.scatter(x_data, y_data)
plt.show()# determine the inputs dtype
x = T.dmatrix("x")
y = T.dmatrix("y")# add layers
l1 = Layer(x, 1, 10, T.nnet.relu)
l2 = Layer(l1.outputs, 10, 1, None)# compute the cost
cost = T.mean(T.square(l2.outputs - y))# compute the gradients
gW1, gb1, gW2, gb2 = T.grad(cost, [l1.W, l1.b, l2.W, l2.b])# apply gradient descent
learning_rate = 0.05
train = theano.function(inputs=[x, y],outputs=[cost],updates=[(l1.W, l1.W - learning_rate * gW1),(l1.b, l1.b - learning_rate * gb1),(l2.W, l2.W - learning_rate * gW2),(l2.b, l2.b - learning_rate * gb2)])# prediction
predict = theano.function(inputs=[x], outputs=l2.outputs)# plot the real data
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.scatter(x_data, y_data)
plt.ion()
plt.show()for i in range(1000):# trainingerr = train(x_data, y_data)if i % 50 == 0:# to visualize the result and improvementtry:ax.lines.remove(lines[0])except Exception:passprediction_value = predict(x_data)# plot the predictionlines = ax.plot(x_data, prediction_value, 'r-', lw=5)plt.pause(.5)

2.分类

3.function用法

4.shared 变量

5.activation function

6.Layer层

7.regression 回归例子

8.classification分类学习

9.过拟合

10.正则化

11.save model

12 总结

http://www.lryc.cn/news/180550.html

相关文章:

  • 【算法优选】双指针专题——贰
  • AI智能电话机器人实用吗
  • 网络爬虫--伪装浏览器
  • C/C++程序的内存开辟
  • 【Java 进阶篇】JDBC DriverManager 详解
  • 2023年Linux总结常用命令
  • Mybatis3详解 之 全局配置文件详解
  • 力扣-345.反转字符串中的元音字母
  • 643. 子数组最大平均数I(滑动窗口)
  • Java 21 新特性:虚拟线程(Virtual Threads)
  • 18scala笔记
  • 【LeetCode周赛】LeetCode第365场周赛
  • 响应式设计的实现方式
  • PHP 反序列化漏洞:__PHP_Incomplete_Class 与 serialize(unserialize($x)) !== $x;
  • TempleteMethod
  • 1558. 得到目标数组的最少函数调用次数
  • 子域名扫描, 后台扫描
  • 毛玻璃带有光影效果的卡片
  • 【Java】面向过程和面向对象思想||对象和类
  • 孤举者难起,众行者易趋,openGauss 5.1.0版本正式发布!
  • 软考——软件设计师中级2023年11月备考(1.计算机组成原理)
  • 前端JavaScript入门到精通,javascript核心进阶ES6语法、API、js高级等基础知识和实战 —— Web APIs(四)
  • 【前端】HTML5 Audio 预加载 按照队列顺序播放音频, 可以陆续往队列中加内容
  • 【单片机】13-实时时钟DS1302
  • springboot和vue:十三、VueX简介与安装与推荐视频+前端数据模拟MockJS
  • [React] Zustand状态管理库
  • 【ChatGPT】ChatGPT发展历史
  • 分布式文件存储系统Minio实战
  • 【MySQL】MySQL 官方安装包形式
  • 使用sqlmap获取数据步骤