我正在尝试按照此处的说明https://github.com/fchollet/hualos 可视化Keras的培训进度。在上述页面中,我读到:
Hualos-Keras总体可视化项目
现在,这是一个简单的演示,其中Flask服务器将API公开给 以JSON对象的形式发布和使用事件。凯拉斯 回调RemoteMonitor可以将事件发布到服务器,并且 Hualos登陆页面侦听服务器并显示传入数据 在c3.js图上。
示例:
start the server: python api.py load the landing page: http://localhost:9000/ launch a Keras experiment with the RemoteMonitor callback:
from keras import callbacks remote =
> callbacks.RemoteMonitor(root='http://localhost:9000')
>
> model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch,
> validation_data=(X_test, Y_test), callbacks=[remote])
此外:
依赖项:
Python: Flask gevent JS (included in the repo): d3.js c3.js
我已经成功安装了Flask和gevent。
以下是我使用mnist测试数据简洁起见的代码,该数据是我从此处以csv文件格式下载的:https://pjreddie.com/projects/mnist-in-csv/
from keras import callbacks
remote = callbacks.RemoteMonitor(root='http://localhost:9000')
X = mnist.iloc[:, 1:].values
y = to_categorical(mnist.iloc[:, 0])
X = X.astype('float32')
y = y.astype('float32')
X /= 255 # ATTENTION! Normalization is critical!!!
n_cols = X.shape[1]
# Create the model: model
model = Sequential()
# Add the first hidden layer
model.add(Dense(50, activation = 'relu', input_shape = (784,)))
# Add the second hidden layer
model.add(Dense(50, activation = 'relu'))
# Add the output layer
model.add(Dense(10, activation = 'softmax'))
# Compile the model
model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
# Fit the model
model.fit(X, y, validation_split = 0.3, epochs=3, callbacks = [remote])
这将产生以下输出:
Train on 7000 samples, validate on 3000 samples
Epoch 1/3
7000/7000 [==============================] - 1s 100us/step - loss: 0.7812 - acc: 0.7717 - val_loss: 0.3036 - val_acc: 0.9153
Epoch 2/3
3296/7000 [=============>................] - ETA: 0s - loss: 0.3139 - acc: 0.9072
C:\ProgramData\Anaconda3\lib\site-packages\keras\callbacks.py:606: UserWarning: Warning: could not reach RemoteMonitor root server at http://localhost:9000
'root server at ' + str(self.root))
7000/7000 [==============================] - 0s 55us/step - loss: 0.3051 - acc: 0.9111 - val_loss: 0.2616 - val_acc: 0.9213
Epoch 3/3
2400/7000 [=========>....................] - ETA: 0s - loss: 0.2613 - acc: 0.9237
C:\ProgramData\Anaconda3\lib\site-packages\keras\callbacks.py:606: UserWarning: Warning: could not reach RemoteMonitor root server at http://localhost:9000
'root server at ' + str(self.root))
7000/7000 [==============================] - 0s 63us/step - loss: 0.2397 - acc: 0.9284 - val_loss: 0.2350 - val_acc: 0.9320
C:\ProgramData\Anaconda3\lib\site-packages\keras\callbacks.py:606: UserWarning: Warning: could not reach RemoteMonitor root server at http://localhost:9000
'root server at ' + str(self.root))
实际上,当我尝试运行命令时:
python api.py
我遇到一个例外:
(base) D:\Mint_ns>python api.py
Traceback (most recent call last):
File "api.py", line 10, in <module>
from pattern.server import App
ModuleNotFoundError: No module named 'pattern'
(base) D:\Mint_ns>conda install -c asmeurer pattern
Solving environment: failed
UnsatisfiableError: The following specifications were found to be in conflict:
- pattern
- tensorflow
Use "conda info <package>" to see the dependencies for each package.
这有点奇怪,因为整个目的是使用Hualos与以TensorFlow作为后端运行的Keras一起工作。
我该如何做?