sigmoid

Estimating high resolution images from lower ones using a Keras model based on ConvLSTM2D

匿名 (未验证) 提交于 2019-12-03 08:50:26
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use the following ConvLSTM2D architecture to estimate high resolution image sequences from low resolution ones: import numpy as np, scipy.ndimage, matplotlib.pyplot as plt from keras.models import Sequential from keras.layers import Dense, Dropout, Activation, Flatten from keras.layers import Convolution2D, ConvLSTM2D, MaxPooling2D, UpSampling2D from sklearn.metrics import accuracy_score, confusion_matrix, cohen_kappa_score from sklearn.preprocessing import MinMaxScaler, StandardScaler np.random.seed(123) raw = np.arange(96)

How to convert deep learning gradient descent equation into python

匿名 (未验证) 提交于 2019-12-03 08:30:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been following an online tutorial on deep learning. It has a practical question on gradient descent and cost calculations where I been struggling to get the given answers once it was converted to python code. Hope you can kindly help me get the correct answer please Please see the following link for the equations used Click here to see the equations used for the calculations Following is the function given to calculate the gradient descent,cost etc. The values need to be found without using for loops but using matrix manipulation

How to calculate a logistic sigmoid function in Python?

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: This is a logistic sigmoid function: I know x. How can I calculate F(x) in Python now? Let's say x = 0.458. F(x) = ? 回答1: This should do it: import math def sigmoid ( x ): return 1 / ( 1 + math . exp (- x )) And now you can test it by calling: >>> sigmoid ( 0.458 ) 0.61253961344091512 Update : Note that the above was mainly intended as a straight one-to-one translation of the given expression into Python code. It is not tested or known to be a numerically sound implementation. If you know you need a very robust implementation, I'm

逻辑回归代码demo

半腔热情 提交于 2019-12-03 07:36:21
概念 代价函数关于参数的偏导 梯度下降法最终的推导公式如下 多分类问题可以转为2分类问题 正则化处理可以防止过拟合,下面是正则化后的代价函数和求导后的式子 正确率和召回率F1指标 我们希望自己预测的结果希望更准确那么查准率就更高,如果希望更获得更多数量的正确结果,那么查全率更重要,综合考虑可以用F1指标 关于正则化为啥可以防止过拟合的理解 梯度下降法实现线性逻辑回归 1 import matplotlib.pyplot as plt 2 import numpy as np 3 from sklearn.metrics import classification_report#分类 4 from sklearn import preprocessing#预测 5 # 数据是否需要标准化 6 scale = True#True是需要,False是不需要,标准化后效果更好,标准化之前可以画图看出可视化结果 7 scale = False 8 # 载入数据 9 data = np.genfromtxt("LR-testSet.csv", delimiter=",") 10 x_data = data[:, :-1] 11 y_data = data[:, -1] 12 13 def plot(): 14 x0 = [] 15 x1 = [] 16 y0 = [] 17 y1 = []

Batch Normalization

心已入冬 提交于 2019-12-03 02:36:43
Batch Normalization作为最近一年来DL的重要成果,已经广泛被证明其有效性和重要性。虽然有些细节处理还解释不清其理论原因,但是实践证明好用才是真的好,别忘了DL从Hinton对深层网络做Pre-Train开始就是一个经验领先于理论分析的偏经验的一门学问。 本文是对论文《Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift》的导读(看看看, 这是通过减少内部协变量移位加速神经网络训练)。 机器学习领域有个很重要的假设:IID独立同分布假设,就是假设训练数据和测试数据是满足相同分布的,这是通过训练数据获得的模型能够在测试集获得好的效果的一个基本保障。那BatchNorm的作用是什么呢?BatchNorm就是在深度神经网络训练过程中使得每一层神经网络的输入保持相同分布的(相同分布是怎样的?是什么的相同分布?参数吗?)。 接下来一步一步的理解什么是BN。 为什么深度神经网络随着网络深度加深,训练起来越困难,收敛越来越慢?这是个在DL领域很接近本质的好问题。很多论文都是解决这个问题的,比如ReLU激活函数,再比如Residual Network,BN本质上也是解释并从某个不同的角度来解决这个问题的(这个解释还是很妙的)。

Tensorflow sigmoid and cross entropy vs sigmoid_cross_entropy_with_logits

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When trying to get cross entropy with sigmoid activation function, there is difference between loss1 = -tf.reduce_sum(p*tf.log(q), 1) loss2 = tf.reduce_sum(tf.nn.sigmoid_cross_entropy_with_logits(labels=p, logits=logit_q),1) But they are same when with softmax activation function. Following is the sample code: import tensorflow as tf sess2 = tf.InteractiveSession() p = tf.placeholder(tf.float32, shape=[None, 5]) logit_q = tf.placeholder(tf.float32, shape=[None, 5]) q = tf.nn.sigmoid(logit_q) sess.run(tf.global_variables_initializer()) feed

Neural Network sigmoid function

匿名 (未验证) 提交于 2019-12-03 01:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to make a neural network and I have a couple of questions: My sigmoid function is like some s = 1/(1+(2.7183**(-self.values))) if s > self.weight: self.value = 1 else: self.value = 0 The self.values is a array of the connected nodes, for instance the HNs(hidden nodes) in the HL(hidden layer) 1 is connected to all input nodes, so it's self.values is sum(inputnodes.values). The HNs in the HL2 is connected to all HNs in HL1, and it's self.values is sum(HL.values) The problem is, every node is getting the value of 1, no mather their

numpy ValueError shapes not aligned

匿名 (未验证) 提交于 2019-12-03 00:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I am trying to adapt the neural network from michael nielson's http://neuralnetworksanddeeplearning.com/chap1.html I modified network.py to work on python 3 and made a small script to test it with a few 15x10 pictures of digits. import os import numpy as np from network import Network from PIL import Image BLACK = 0 WHITE = 255 cdir = "cells" cells = [] for cell in os.listdir(cdir): img = Image.open(os.path.join(cdir,cell)) number = cell.split(".")[0][-1] pixels = img.load() pdata = [] for x in range(img.width): for y in range(img.height)

反向传播算法

匿名 (未验证) 提交于 2019-12-03 00:38:01
本文用于学习反向传播算法!!! #单隐层神经网络使用反向传播算法训练模型 import numpy as np #使用sigmoid激活函数 def sigmoid(x,deriv=False): if(deriv==True): return (1-x)*x return 1/(1+np.exp(-x)) #训练数据集 x=np.array([[0,0,1], [0,1,1], [1,0,1], [1,1,1], [0,0,1]]) y=np.array([[0], [1], [1], [0], [0]]) #权重随机初始化 np.random.seed(2) w0 = 2*np.random.random((3,4))-1 w1 = 2*np.random.random((4,1))-1 for i in range(10000): #前向传播 l0 = x l1 = sigmoid(np.dot(l0,w0)) l2 = sigmoid(np.dot(l1,w1)) l2_error = -(y-l2) if(i%1000==0): print("error"+str(np.mean(np.abs(l2_error)))) #反向传播 l2_delta = l2_error*sigmoid(l2,True) #输出层的误差 w_ho_pd = l1.T.dot(l2

深度学习剖根问底:梯度消失以及爆炸

匿名 (未验证) 提交于 2019-12-03 00:36:02
转载自:https://blog.csdn.net/qq_25737169/article/details/78847691 前言 其中,梯度消失爆炸的解决方案主要包括以下几个部分。 - 预训练加微调 - 梯度剪切、权重正则(针对梯度爆炸) - 使用不同的激活函数 - 使用batchnorm - 使用残差结构 - 使用LSTM网络 第一部分:为什么要使用梯度更新规则 我们最终的目的是希望这个多元函数可以很好的完成输入到输出之间的映射,假设不同的输入,输出的最优解是 取得极小值点,比如最简单的损失函数 第二部分:梯度消失、爆炸 梯度消失与梯度爆炸其实是一种情况,看接下来的文章就知道了。两种情况下梯度消失经常出现,一是在 深层网络 中,二是采用了 不合适的损失函数 ,比如sigmoid。梯度爆炸一般出现在深层网络和 权值初始化值太大 的情况下,下面分别从这两个角度分析梯度消失和爆炸的原因。 1.深层网络角度 图中的曲线表示权值更新的速度,对于下图两个隐层的网络来说,已经可以发现隐藏层2的权值更新速度要比隐藏层1更新的速度慢 那么对于四个隐层的网络来说,就更明显了,第四隐藏层比第一隐藏层的更新速度慢了两个数量级: 总结: 从深层网络角度来讲,不同的层学习的速度差异很大,表现为网络中靠近输出的层学习的情况很好,靠近输入的层学习的很慢,有时甚至训练了很久