【画图】基于Python的神经网络可视化工具

举报
王博Kings 发表于 2020/12/29 22:51:37 2020/12/29
【摘要】 项目链接: https://github.com/Prodicode/ann-visualizer?utm_source=mybridge&utm_medium=blog&utm_campaign=read_more A python library for visualizing Artificial Neural Networks (ANN) 如何安装 Fro...

项目链接:

https://github.com/Prodicode/ann-visualizer?utm_source=mybridge&utm_medium=blog&utm_campaign=read_more

A python library for visualizing Artificial Neural Networks (ANN)

如何安装

From Github

  1. Download the ann_visualizer folder from the github repository.
  2. Place the ann_visualizer folder in the same directory as your main python script.

From pip

Use the following command:

pip3 install ann_visualizer
 

Make sure you have graphviz installed. Install it using:

sudo apt-get install graphviz && pip3 install graphviz
 

人工神经网络绘图示例


  
  1. import keras;
  2. from keras.models import Sequential;
  3. from keras.layers import Dense;
  4. network = Sequential();
  5. #Hidden Layer#1
  6. network.add(Dense(units=6,
  7. activation='relu',
  8. kernel_initializer='uniform',
  9. input_dim=11));
  10. #Hidden Layer#2
  11. network.add(Dense(units=6,
  12. activation='relu',
  13. kernel_initializer='uniform'));
  14. #Exit Layer
  15. network.add(Dense(units=1,
  16. activation='sigmoid',
  17. kernel_initializer='uniform'));
  18. from ann_visualizer.visualize import ann_viz;
  19. ann_viz(network, title="");

卷积神经网络绘图示例


  
  1. import keras;
  2. from keras.models import Sequential;
  3. from keras.layers import Dense;
  4. from ann_visualizer.visualize import ann_viz
  5. model = build_cnn_model()
  6. ann_viz(model, title="")
  7. def build_cnn_model():
  8. model = keras.models.Sequential()
  9. model.add(
  10. Conv2D(
  11. 32, (3, 3),
  12. padding="same",
  13. input_shape=(32, 32, 3),
  14. activation="relu"))
  15. model.add(Dropout(0.2))
  16. model.add(
  17. Conv2D(
  18. 32, (3, 3),
  19. padding="same",
  20. input_shape=(32, 32, 3),
  21. activation="relu"))
  22. model.add(MaxPooling2D(pool_size=(2, 2)))
  23. model.add(Dropout(0.2))
  24. model.add(
  25. Conv2D(
  26. 64, (3, 3),
  27. padding="same",
  28. input_shape=(32, 32, 3),
  29. activation="relu"))
  30. model.add(Dropout(0.2))
  31. model.add(
  32. Conv2D(
  33. 64, (3, 3),
  34. padding="same",
  35. input_shape=(32, 32, 3),
  36. activation="relu"))
  37. model.add(MaxPooling2D(pool_size=(2, 2)))
  38. model.add(Dropout(0.2))
  39. model.add(Flatten())
  40. model.add(Dense(512, activation="relu"))
  41. model.add(Dropout(0.2))
  42. model.add(Dense(10, activation="softmax"))
  43. return model

 

文章来源: kings.blog.csdn.net,作者:人工智能博士,版权归原作者所有,如需转载,请联系作者。

原文链接:kings.blog.csdn.net/article/details/89891005

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。