吴恩达作业7:梯度下降优化算法

先说说BatchGD用整个训练样本进行训练得出损失值,SGD是只用一个训练样本训练就得出损失值,GD导致训练慢,SGD导致收敛到最小值不平滑,故引入Mini-batch GD,选取部分样本进行训练得出损失值,

普通梯度下降算法如下:

""""
一般梯度下降算法
"""
def update_parameters_gd(parameters,grads,learning_rate):L=len(parameters)//2for i in range(L):parameters['W'+str(i+1)]=parameters['W'+str(i+1)]-learning_rate*grads['dW'+str(i+1)]parameters['b' + str(i + 1)] = parameters['b' + str(i + 1)] - learning_rate * grads['db' + str(i + 1)]return parameters

Momentum代码:

"""
Momentum初始化参数
"""
def initialize_Momentum_paremeters(parameters):L=len(parameters)//2v={}for i in range(L):v['dW'+str(i+1)]=np.zeros(parameters['W'+str(i+1)].shape)v['db' + str(i + 1)] = np.zeros(parameters['b' + str(i + 1)].shape)return v
"""
Momentum更新权重
"""
def upate_parameters_Momentum(parameters,grads,v,beta,learning_rate):L=len(parameters)//2for i in range(L):v['dW' + str(i + 1)]=beta*v['dW'+str(i+1)]+(1-beta)*grads['dW'+str(i+1)]v['db' + str(i + 1)] = beta * v['db' + str(i + 1)] + (1 - beta) * grads['db' + str(i + 1)]parameters['W'+str(i+1)]=parameters['W'+str(i+1)]-learning_rate*v['dW' + str(i + 1)]parameters['b' + str(i + 1)] = parameters['b' + str(i + 1)] - learning_rate * v['db' + str(i + 1)]return parameters,v

Adam代码:

"""
Adam初始化参数
"""
def initialize_Adam_parameters(parameters):L=len(parameters)//2v={}s={}for i in range(L):v['dW' + str(i + 1)] = np.zeros(parameters['W'+str(i+1)].shape)v['db' + str(i + 1)] = np.zeros(parameters['b' + str(i + 1)].shape)s['dW' + str(i + 1)] = np.zeros(parameters['W' + str(i + 1)].shape)s['db' + str(i + 1)] = np.zeros(parameters['b' + str(i + 1)].shape)return v,s
"""
Adam更新权重
"""
def update_parameters_Adam(parameters,grads,v,s,t,beta1,beta2,learning_rate,epsilon):L = len(parameters) // 2v_correct={}s_correct = {}for i in range(L):v['dW' + str(i + 1)] = beta1 * v['dW' + str(i + 1)] + (1 - beta1) * grads['dW' + str(i + 1)]v['db' + str(i + 1)] = beta1 * v['db' + str(i + 1)] + (1 - beta1) * grads['db' + str(i + 1)]v_correct['dW' + str(i + 1)]=v['dW' + str(i + 1)]/(1-beta1**t)v_correct['db' + str(i + 1)] = v['db' + str(i + 1)] / (1 - beta1 ** t)s['dW' + str(i + 1)] = beta2 * s['dW' + str(i + 1)] + (1 - beta2) * np.square(grads['dW' + str(i + 1)])s['db' + str(i + 1)] = beta2 * s['db' + str(i + 1)] + (1 - beta2) * np.square(grads['db' + str(i + 1)])s_correct['dW' + str(i + 1)] = s['dW' + str(i + 1)] / (1 - beta2 ** t)s_correct['db' + str(i + 1)] = s['db' + str(i + 1)] / (1 - beta2 ** t)parameters['W' + str(i + 1)] = parameters['W' + str(i + 1)] - \learning_rate * (v_correct['dW' + str(i + 1)]/(np.sqrt(s['dW' + str(i + 1)])+epsilon))parameters['b' + str(i + 1)] = parameters['b' + str(i + 1)] - \learning_rate * (v_correct['db' + str(i + 1)]/(np.sqrt(s['db' + str(i + 1)])+epsilon))return parameters, v,s

数据集 放在opt_utils.py   代码如下:还包含激活函数 前向传播 后向传播等函数

import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy.io
import sklearn
import sklearn.datasetsdef sigmoid(x):"""Compute the sigmoid of xArguments:x -- A scalar or numpy array of any size.Return:s -- sigmoid(x)"""s = 1/(1+np.exp(-x))return sdef relu(x):"""Compute the relu of xArguments:x -- A scalar or numpy array of any size.Return:s -- relu(x)"""s = np.maximum(0,x)return sdef load_params_and_grads(seed=1):np.random.seed(seed)W1 = np.random.randn(2,3)b1 = np.random.randn(2,1)W2 = np.random.randn(3,3)b2 = np.random.randn(3,1)dW1 = np.random.randn(2,3)db1 = np.random.randn(2,1)dW2 = np.random.randn(3,3)db2 = np.random.randn(3,1)return W1, b1, W2, b2, dW1, db1, dW2, db2def initialize_parameters(layer_dims):"""Arguments:layer_dims -- python array (list) containing the dimensions of each layer in our networkReturns:parameters -- python dictionary containing your parameters "W1", "b1", ..., "WL", "bL":W1 -- weight matrix of shape (layer_dims[l], layer_dims[l-1])b1 -- bias vector of shape (layer_dims[l], 1)Wl -- weight matrix of shape (layer_dims[l-1], layer_dims[l])bl -- bias vector of shape (1, layer_dims[l])Tips:- For example: the layer_dims for the "Planar Data classification model" would have been [2,2,1]. This means W1's shape was (2,2), b1 was (1,2), W2 was (2,1) and b2 was (1,1). Now you have to generalize it!- In the for loop, use parameters['W' + str(l)] to access Wl, where l is the iterative integer."""np.random.seed(3)parameters = {}L = len(layer_dims) # number of layers in the networkfor l in range(1, L):parameters['W' + str(l)] = np.random.randn(layer_dims[l], layer_dims[l-1])*  np.sqrt(2 / layer_dims[l-1])parameters['b' + str(l)] = np.zeros((layer_dims[l], 1))assert(parameters['W' + str(l)].shape == layer_dims[l], layer_dims[l-1])assert(parameters['W' + str(l)].shape == layer_dims[l], 1)return parametersdef compute_cost(a3, Y):"""Implement the cost functionArguments:a3 -- post-activation, output of forward propagationY -- "true" labels vector, same shape as a3Returns:cost - value of the cost function"""m = Y.shape[1]logprobs = np.multiply(-np.log(a3),Y) + np.multiply(-np.log(1 - a3), 1 - Y)cost = 1./m * np.sum(logprobs)return costdef forward_propagation(X, parameters):"""Implements the forward propagation (and computes the loss) presented in Figure 2.Arguments:X -- input dataset, of shape (input size, number of examples)parameters -- python dictionary containing your parameters "W1", "b1", "W2", "b2", "W3", "b3":W1 -- weight matrix of shape ()b1 -- bias vector of shape ()W2 -- weight matrix of shape ()b2 -- bias vector of shape ()W3 -- weight matrix of shape ()b3 -- bias vector of shape ()Returns:loss -- the loss function (vanilla logistic loss)"""# retrieve parametersW1 = parameters["W1"]b1 = parameters["b1"]W2 = parameters["W2"]b2 = parameters["b2"]W3 = parameters["W3"]b3 = parameters["b3"]# LINEAR -> RELU -> LINEAR -> RELU -> LINEAR -> SIGMOIDz1 = np.dot(W1, X) + b1a1 = relu(z1)z2 = np.dot(W2, a1) + b2a2 = relu(z2)z3 = np.dot(W3, a2) + b3a3 = sigmoid(z3)cache = (z1, a1, W1, b1, z2, a2, W2, b2, z3, a3, W3, b3)return a3, cachedef backward_propagation(X, Y, cache):"""Implement the backward propagation presented in figure 2.Arguments:X -- input dataset, of shape (input size, number of examples)Y -- true "label" vector (containing 0 if cat, 1 if non-cat)cache -- cache output from forward_propagation()Returns:gradients -- A dictionary with the gradients with respect to each parameter, activation and pre-activation variables"""m = X.shape[1](z1, a1, W1, b1, z2, a2, W2, b2, z3, a3, W3, b3) = cachedz3 = 1./m * (a3 - Y)dW3 = np.dot(dz3, a2.T)db3 = np.sum(dz3, axis=1, keepdims = True)da2 = np.dot(W3.T, dz3)dz2 = np.multiply(da2, np.int64(a2 > 0))dW2 = np.dot(dz2, a1.T)db2 = np.sum(dz2, axis=1, keepdims = True)da1 = np.dot(W2.T, dz2)dz1 = np.multiply(da1, np.int64(a1 > 0))dW1 = np.dot(dz1, X.T)db1 = np.sum(dz1, axis=1, keepdims = True)gradients = {"dz3": dz3, "dW3": dW3, "db3": db3,"da2": da2, "dz2": dz2, "dW2": dW2, "db2": db2,"da1": da1, "dz1": dz1, "dW1": dW1, "db1": db1}return gradientsdef predict(X, y, parameters):"""This function is used to predict the results of a  n-layer neural network.Arguments:X -- data set of examples you would like to labelparameters -- parameters of the trained modelReturns:p -- predictions for the given dataset X"""m = X.shape[1]p = np.zeros((1,m), dtype = np.int)# Forward propagationa3, caches = forward_propagation(X, parameters)# convert probas to 0/1 predictionsfor i in range(0, a3.shape[1]):if a3[0,i] > 0.5:p[0,i] = 1else:p[0,i] = 0# print results#print ("predictions: " + str(p[0,:]))#print ("true labels: " + str(y[0,:]))print("Accuracy: "  + str(np.mean((p[0,:] == y[0,:]))))return pdef load_2D_dataset():data = scipy.io.loadmat('datasets/data.mat')train_X = data['X'].Ttrain_Y = data['y'].Ttest_X = data['Xval'].Ttest_Y = data['yval'].Tplt.scatter(train_X[0, :], train_X[1, :], c=train_Y, s=40, cmap=plt.cm.Spectral);return train_X, train_Y, test_X, test_Ydef plot_decision_boundary(model, X, y):# Set min and max values and give it some paddingx_min, x_max = X[0, :].min() - 1, X[0, :].max() + 1y_min, y_max = X[1, :].min() - 1, X[1, :].max() + 1h = 0.01# Generate a grid of points with distance h between themxx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))# Predict the function value for the whole gridZ = model(np.c_[xx.ravel(), yy.ravel()])Z = Z.reshape(xx.shape)# Plot the contour and training examplesplt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)plt.ylabel('x2')plt.xlabel('x1')plt.scatter(X[0, :], X[1, :], c=y, cmap=plt.cm.Spectral)plt.show()def predict_dec(parameters, X):"""Used for plotting decision boundary.Arguments:parameters -- python dictionary containing your parameters X -- input data of size (m, K)Returnspredictions -- vector of predictions of our model (red: 0 / blue: 1)"""# Predict using forward propagation and a classification threshold of 0.5a3, cache = forward_propagation(X, parameters)predictions = (a3 > 0.5)return predictionsdef load_dataset():np.random.seed(3)#(300,2)  (300,)train_X, train_Y = sklearn.datasets.make_moons(n_samples=300, noise=.2) #300 #0.2 #print(train_X,train_Y)# Visualize the data#plt.scatter(train_X[:, 0], train_X[:, 1], c=train_Y, s=40, cmap=plt.cm.Spectral);train_X = train_X.Ttrain_Y = train_Y.reshape((1, train_Y.shape[0]))return train_X, train_Y

打印数据集看看:

全部代码:

import numpy as np
import sklearn
import matplotlib.pyplot as plt
import sklearn
import sklearn.datasets
import scipy.io
import math
import opt_utils
import testCases1
""""
一般梯度下降算法
"""
def update_parameters_gd(parameters,grads,learning_rate):L=len(parameters)//2for i in range(L):parameters['W'+str(i+1)]=parameters['W'+str(i+1)]-learning_rate*grads['dW'+str(i+1)]parameters['b' + str(i + 1)] = parameters['b' + str(i + 1)] - learning_rate * grads['db' + str(i + 1)]return parameters
""""
制作样本 mini-batch
"""
def random_mini_batches(X,Y,mini_batch_size):m=X.shape[1]###3mini_batchs=[]permutation = list(np.random.permutation(m))#[2,1,0]shuffled_X = X[:,permutation]##X[:,[2,1,0]] 洗牌shuffled_Y = Y[:, permutation]  ##X[:,[2,1,0]]num_mini_batch=math.floor(m/mini_batch_size)for i in range(num_mini_batch):mini_batch_X=shuffled_X[:,i*mini_batch_size:(i+1)*mini_batch_size]mini_batch_Y=shuffled_Y[:,i*mini_batch_size:(i+1)*mini_batch_size]mini_batch=(mini_batch_X,mini_batch_Y)mini_batchs.append(mini_batch)if m/mini_batch_size!=0:mini_batch_X = shuffled_X[:, (i + 1) * mini_batch_size:]mini_batch_Y = shuffled_Y[:, (i + 1) * mini_batch_size:]mini_batch = (mini_batch_X, mini_batch_Y)mini_batchs.append(mini_batch)return mini_batchs
"""
Momentum初始化参数
"""
def initialize_Momentum_paremeters(parameters):L=len(parameters)//2v={}for i in range(L):v['dW'+str(i+1)]=np.zeros(parameters['W'+str(i+1)].shape)v['db' + str(i + 1)] = np.zeros(parameters['b' + str(i + 1)].shape)return v
"""
Momentum更新权重
"""
def upate_parameters_Momentum(parameters,grads,v,beta,learning_rate):L=len(parameters)//2for i in range(L):v['dW' + str(i + 1)]=beta*v['dW'+str(i+1)]+(1-beta)*grads['dW'+str(i+1)]v['db' + str(i + 1)] = beta * v['db' + str(i + 1)] + (1 - beta) * grads['db' + str(i + 1)]parameters['W'+str(i+1)]=parameters['W'+str(i+1)]-learning_rate*v['dW' + str(i + 1)]parameters['b' + str(i + 1)] = parameters['b' + str(i + 1)] - learning_rate * v['db' + str(i + 1)]return parameters,v
"""
Adam初始化参数
"""
def initialize_Adam_parameters(parameters):L=len(parameters)//2v={}s={}for i in range(L):v['dW' + str(i + 1)] = np.zeros(parameters['W'+str(i+1)].shape)v['db' + str(i + 1)] = np.zeros(parameters['b' + str(i + 1)].shape)s['dW' + str(i + 1)] = np.zeros(parameters['W' + str(i + 1)].shape)s['db' + str(i + 1)] = np.zeros(parameters['b' + str(i + 1)].shape)return v,s
"""
Adam更新权重
"""
def update_parameters_Adam(parameters,grads,v,s,t,beta1,beta2,learning_rate,epsilon):L = len(parameters) // 2v_correct={}s_correct = {}for i in range(L):v['dW' + str(i + 1)] = beta1 * v['dW' + str(i + 1)] + (1 - beta1) * grads['dW' + str(i + 1)]v['db' + str(i + 1)] = beta1 * v['db' + str(i + 1)] + (1 - beta1) * grads['db' + str(i + 1)]v_correct['dW' + str(i + 1)]=v['dW' + str(i + 1)]/(1-beta1**t)v_correct['db' + str(i + 1)] = v['db' + str(i + 1)] / (1 - beta1 ** t)s['dW' + str(i + 1)] = beta2 * s['dW' + str(i + 1)] + (1 - beta2) * np.square(grads['dW' + str(i + 1)])s['db' + str(i + 1)] = beta2 * s['db' + str(i + 1)] + (1 - beta2) * np.square(grads['db' + str(i + 1)])s_correct['dW' + str(i + 1)] = s['dW' + str(i + 1)] / (1 - beta2 ** t)s_correct['db' + str(i + 1)] = s['db' + str(i + 1)] / (1 - beta2 ** t)parameters['W' + str(i + 1)] = parameters['W' + str(i + 1)] - \learning_rate * (v_correct['dW' + str(i + 1)]/(np.sqrt(s['dW' + str(i + 1)])+epsilon))parameters['b' + str(i + 1)] = parameters['b' + str(i + 1)] - \learning_rate * (v_correct['db' + str(i + 1)]/(np.sqrt(s['db' + str(i + 1)])+epsilon))return parameters, v,s
def model(X,Y,layer_dims,optimizer,learning_rate,mini_batch_size,beta,beta1,beta2,epsilon,num_pochs):t=0costs=[]parameters=opt_utils.initialize_parameters(layer_dims)if optimizer=='gd':passelif optimizer=='Momentum':v=initialize_Momentum_paremeters(parameters)elif optimizer=='Adam':v, s=initialize_Adam_parameters(parameters)for i in range(num_pochs):mini_batchs=random_mini_batches(X,Y,mini_batch_size)   ###[([X],[Y]),([X2],[Y2])]for minibatch in mini_batchs:(minibatch_X,minibatch_Y)=minibatchA3, cache=opt_utils.forward_propagation(minibatch_X,parameters)cost=opt_utils.compute_cost(A3,minibatch_Y)gradients=opt_utils.backward_propagation(minibatch_X, minibatch_Y, cache)if optimizer=='gd':parameters=update_parameters_gd(parameters,gradients,learning_rate)elif optimizer=='Momentum':parameters, v=upate_parameters_Momentum(parameters, gradients, v, beta, learning_rate)elif optimizer=='Adam':t=t+1parameters, v, s=update_parameters_Adam(parameters, gradients, v, s, t, beta1, beta2, learning_rate, epsilon)if i%1000==0:costs.append(cost)print('after {} epochs cost={}'.format(i,cost) )plt.plot(costs)plt.xlabel('num_pochs(per 100)')plt.ylabel('costs')plt.title('learning_rate={}'.format(learning_rate))plt.savefig('Adam.jpg')plt.show()return parameters
def test():
############test mini_batch# X, Y, mini_batch_size=testCases1.random_mini_batches_test_case()# mini_batchs=random_mini_batches(X, Y, mini_batch_size=64)# print('first x shape={}'.format(mini_batchs[0][0].shape))# print('second x shape={}'.format(mini_batchs[1][0].shape))# print('third x shape={}'.format(mini_batchs[2][0].shape))# print('first y shape={}'.format(mini_batchs[0][1].shape))# print('second y shape={}'.format(mini_batchs[1][1].shape))# print('third y shape={}'.format(mini_batchs[2][1].shape))
###############
#######test initialize_vecolity# parameters=testCases1.initialize_velocity_test_case()# v=initialize_velocity(parameters)# print(v)
####################
#######test upate_parameters_Momentum# parameters, grads, v=testCases1.update_parameters_with_momentum_test_case()# parameters, v=upate_parameters_Momentum(parameters,grads,v,beta=0.9,learning_rate=0.01)# print(parameters)# print(v)
###############
########test upate_parameters_Adamparameters, grads, v, s=testCases1.update_parameters_with_adam_test_case()parameters, v, s=update_parameters_Adam(parameters,grads,v,s,t=2,beta1=0.9,beta2=0.999,learning_rate=0.01,epsilon=1e-8)print(parameters,v,s)
def test_model():train_X, train_Y=opt_utils.load_dataset()layer_dims=[train_X.shape[0],5,2,1]parameters=model(train_X,train_Y,layer_dims,optimizer='gd',learning_rate=0.0007,mini_batch_size=64,beta=0.9,beta1=0.9,beta2=0.999,epsilon=1e-8,num_pochs=10000)opt_utils.predict(train_X, train_Y, parameters)
if __name__=='__main__':#test()test_model()

更改model()里的optimizer即可,普通梯度下降法结果:

Momentum下降结果和上面结果差不多可能是学习率太小,数据集太简单导致的吧

Adam下降结果,能够更快的收敛

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/493614.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

什么是单应矩阵和本质矩阵

知乎上面的大牛还是很多,直接搜Homography或者单应矩阵就能得到很多大神的回答,可能回答中的一句话或者一个链接就够自己学习很久。 其实在之前研究双目视觉的时候就接触了对极几何,通过视觉就可以得到物体的远近信息,这也是特斯…

tensorflow实现反卷积

先看ogrid用法 from numpy import ogrid,repeat,newaxis from skimage import io import numpy as np size3 x,yogrid[:size,:size]#第一部分产生多行一列 第二部分产生一行多列 print(x) print(y) 打印结果: newaxis用法: """ newaxis…

寿命能推算吗?加州大学科学家提出“预测方法”

来源:中国科学报从古至今,从国内到国外,从炼丹术到现代科学,长生不老似乎一直是人类乐此不疲的追求。但若要延缓衰老,首先要弄清是什么造成了衰老。近日,加州大学洛杉矶分校(UCLA)生…

Deep Image Homography Estimation

在知乎问题:深度学习应用在哪些领域让你觉得「我去,这也能行!」?中遇到一篇提交在arXiv 2016(arXiv不是正式发表,只是可以证明原创性,提供时间戳的网站)的文章《Deep Image Homograp…

tensorflow:双线性插值反卷积

首先生成333的黑色图片 """ 生成333黑色图像 """ def produce_image():size 3x, y ogrid[:size, :size] # 第一部分产生多行一列 第二部分产生一行多列z x yz z[:, :, newaxis] # 增加第三维# print(z)img repeat(z, 3, 2)/12 # 在第三…

腾讯医疗AI新突破:提出器官神经网络,全自动辅助头颈放疗规划 | 论文

来源:量子位腾讯医疗AI实验室又有新研究。这次跟美国加州大学合作,在国际权威期刊《Medical Physics》发表最新研究成果:《器官神经网络:深度学习用于快速和全自动整体头颈危及器官靶区勾画》AnatomyNet: Deep Learning for Fast …

视频制作中的绿幕与拜耳阵列

先来欣赏一些大片背后的特效。 现在国内的电影市场越来越大,做短视频的自媒体也越来越多,在他们的后期视频制作的片花中可以看到很多都在使用绿幕或者蓝幕,这是为什么呢? 首先肯定是为了抠图的方便。将主体部分抠出再将通过特效…

吴恩达作业8:三层神经网络实现手势数字的识别(基于tensorflow)

数据集的载入,随机产生mini-batch放在tf_utils.py,代码如下 import h5py import numpy as np import tensorflow as tf import mathdef load_dataset():train_dataset h5py.File(datasets/train_signs.h5, "r")train_set_x_orig np.array(train_datase…

基于visual Studio2013解决面试题之0307最后谁剩下

题目解决代码及点评/* n 个数字(0,1,…,n-1)形成一个圆圈,从数字 0 开始,每次从这个圆圈中删除第 m 个数字(第一个为当前数字本身,第二个为当前数字的下一个数字&…

谷歌、苹果等大佬亲自戳穿自动驾驶完美童话,技术、场景、安全牢笼实难突围!...

来源: 物联网智库摘要:自动驾驶普及不仅局限于自身技术和应用场景,而且与产业链各环节密切相关。一项科技从诞生到被人们所接受是一个循序渐进的过程,自动驾驶真正普及还任重而道远。2018年11月1日百度世界大会上,百度…

使用文件监控对象FileSystemWatcher实现数据同步

使用文件监控对象FileSystemWatcher实现数据同步 原文 使用文件监控对象FileSystemWatcher实现数据同步 最近在项目中有这么个需求,就是得去实时获取某个在无规律改变的文本文件中的内 容。首先想到的是用程序定期去访问这个文件,因为对实时性要求很高&a…

吴恩达作业11:残差网络实现手势数字的识别(基于 keras)+tensorbord显示loss值和acc值

一,残差网络实现手写数字识别 数据集地址:https://download.csdn.net/download/fanzonghao/10551018 首先来resnets_utils.py,里面有手势数字的数据集载入函数和随机产生mini-batch的函数,代码如下: import os import numpy as…

通过SVD求解单应矩阵

我们现在知道原则上4对匹配点对就可以唯一确定单应矩阵,但是在实际应用中我们无法保证两个视图严格满足使用条件(只有旋转变换;远景;平面场景),所以要使用拟合的方法求一个最优解。现在就来以SIFT算法源码为…

注意力机制(Attention)最新综述论文及相关源码

来源:专知注意力机制(Attention)起源于模仿人类的思维方式,后被广泛应用于机器翻译、情感分类、自动摘要、自动问答等、依存分析等机器学习应用中。专知编辑整理了Arxiv上一篇关于注意力机制在NLP中应用的综述《An Introductory Survey on Attention Mec…

橙子楼的猥琐大叔

故事要从暑假开始说起,那时我还在准备考研,每天往返于教室、宿舍和食堂,单调但不会无趣,常常会有故事发生,生活也很充实。 考研的一般都会在固定的教室有个自己的位子。 坐我正前面的是一个妹子,准确的说是…

Pycharm下安装Tensorflow

趁着帮师妹看Github上的一个项目,督促自己学习一下Python下训练神经网络的一整套流程。没想到在一开头就遇到了不少问题。首先是Pycharm中导入Github项目的问题,还有安装tensorflow的问题,之后又遇到了多种版本的Python共存的问题。在这里记录…

吴恩达作业9:卷积神经网络实现手势数字的识别(基于tensorflow)

数据集链接:https://download.csdn.net/download/fanzonghao/10551018 提供数据集代码放在cnn_utils.py里。 import math import numpy as np import h5py import matplotlib.pyplot as plt import tensorflow as tf from tensorflow.python.framework import ops…

AI洞观 | 戴上红帽 看IBM冲杀云计算市场

来源 | 网易智能(公众号 smartman163)摘要:可以预计,未来的云计算市场将越来越比拼生态综合服务能力,云计算行业进入下半场,谁在裸泳不久见分晓。IBM豪掷340亿美元收购红帽(Red Hat)…

基于visual Studio2013解决面试题之0608找出两个只出现一次的数

题目解决代码及点评/*已知数组中有两个数只出现一次,其他成对出现,请找出这两个数解决办法:1)简化问题,如果数组中只有一个数出现一次,那么只要对这个数组做异或即可2…

工业富联:左手工业AI,右手“雾小脑”

来源:先进制造业摘要:11月14日,第二十届中国国际高新技术成果交易会在深圳会展中心开幕。11月14日,第二十届中国国际高新技术成果交易会在深圳会展中心开幕。备受瞩目的是,在分论坛“2018第九届中国信息通信论坛”上&a…