这个模块安装的坑不是一般的多,终于搞定了
我的keras 版本是
(C:\ProgramData\Anaconda2) C:\Users\lg>python
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 19 2016, 13:29:36) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
1.1 命令行输入 pip install graphviz
1.2 安装graphviz软件。官网地址为http://www.graphviz.org/
官网中有解压版和安装版,推荐解压版,因为我使用解压版成功了,安装版好像出了点问题- -
解压版:
http://www.graphviz.org/pub/graphviz/stable/windows/graphviz-2.38.zip
1.3 将安装目录中的graphviz-2.38\release\bin添加进Path环境变量
命令行输入pip install pydot==1.1.0
网上说的安装pydot的方法五花八门,有一种是 pip install pydot==1.1.0 这种方法是针对python2可以,
但是python3就不行了,因为Python3安装的1.2.*版本里面有所变动,可视化的地方需要用到visualize_util这样一个api,但是在1.2.*中,这个api被取消掉了,所以python3的用户应该安装 pydot_ng
# -*- coding: utf-8 -*-
"""
Created on Thu May 04 10:48:13 2017
import numpy as np
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.optimizers import SGD
from keras.utils import np_utils
from keras.utils.vis_utils import plot_model
def run():
# 构建神经网络
model = Sequential()
model.add(Dense(4, input_dim=2, init='uniform'))
model.add(Activation('relu'))
model.add(Dense(2, init='uniform'))
model.add(Activation('sigmoid'))
sgd = SGD(lr=0.05, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['accuracy'])
# 神经网络可视化
plot_model(model, to_file='model.png')
if __name__ == '__main__':
run()
show_shapes=true