加入收藏 | 设为首页 | 会员中心 | 我要投稿 西安站长网 (https://www.029zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 建站 > 正文

看懂这篇指南,包你掌握神经网络的“黑匣子”

发布时间:2019-06-04 18:09:32 所属栏目:建站 来源:读芯术
导读:副标题#e# 人类的神经网络是如何运行的?这个问题让很多数据科学家感到困惑。解释某个简单神经网络的工作机制非常容易,但是当某个计算机视觉项目中的层数增加1000倍时,该怎么办呢? 终端用户想要了解模型是如何得到最终结果时,仅用纸和笔来解释深度神经网

通过下面的图片来理解最大激活的概念:

看懂这篇指南,包你掌握神经网络的“黑匣子”

在识别大象的过程中,哪些特征比较重要?

下面是一些较容易想到的特征。

  • 獠牙
  • 象鼻
  • 耳朵

这就是人类凭直觉判别大象的方式。但是,使用卷积神经网络优化随机图像,并尝试将其归类为大象时,会得到什么结果呢?

卷积神经网络中,每个卷积层都在前一层的输出中寻找相似的模式。当输入包含其正在寻找的模式时,就能实现最大激活。

在激活最大化技术中,更新每一层的输入,使该过程中的损失达到最小值。

应该怎么做呢?首先需要计算激活损失相对于输入的梯度,并据此更新输入。

看懂这篇指南,包你掌握神经网络的“黑匣子”

以下为所述方法的代码:

  1. #importing the required modules 
  2. from vis.visualization import visualize_activation 
  3. from vis.utils import utils 
  4. from keras import activations 
  5. from keras import applications 
  6. import matplotlib.pyplot as plt 
  7. %matplotlib inline 
  8. plt.rcParams['figure.figsize'] = (18,6) 
  9. #creating a VGG16 model using fully connected layers also because then we can  
  10. #visualize the patterns for individual category 
  11. from keras.applications import VGG16 
  12. model = VGG16(weights='imagenet',include_top=True) 
  13.  
  14. #finding out the layer index using layer name 
  15. #the find_layer_idx function accepts the model and name of layer as parameters and return the index of respective layer 
  16. layer_idx = utils.find_layer_idx(model,'predictions') 
  17. #changing the activation of the layer to linear 
  18. model.layers[layer_idx].activation = activations.linear 
  19. #applying modifications to the model 
  20. model = utils.apply_modifications(model) 
  21. #Indian elephant 
  22. img3 = visualize_activation(model,layer_idx,filter_indices=385,max_iter=5000,verbose=True) 
  23. plt.imshow(img3) 

(编辑:西安站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读