python - 使用 Hualos 可视化 Keras 中的训练进度
问题描述
我正在尝试按照此处的说明https://github.com/fchollet/hualos 来可视化 Keras 中的训练进度。在上述页面中,我读到:
Hualos - Keras 全面可视化项目
目前,这是一个简单的演示,其中 Flask 服务器公开了一个 API,以 JSON 对象的形式发布和使用事件。Keras 回调 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 一起工作。
我怎样才能使这项工作?
解决方案
推荐阅读
- android - 从什么时候android在崩溃后重新启动应用程序?
- php - MySQL 在 DB Array 字段中查找数组值
- flutter - flutter_local_notifications 事件不起作用
- angular - 从服务器加载数据时的角度组件空白几秒钟
- reactjs - 在无限循环中动态添加和删除 className
- javascript - 计算属性无法正确获取数据 Vue.js ,
- php - Laravel orWhere 查询无法正常工作
- java - 在 java 中创建受密码保护的 zip 文件,在解压过程中我得到文件不支持的问题
- ssh - 如何使用分配给 SIM7600E 4G HAT 的静态 IP 访问 Raspberry PI 4 的 ssh?
- c# - 如何使用 Vue.js 和 .NET Core API 设置 Active Directory 身份验证