comet (comet-ml) 无法使用 Keras 运行

comet (comet-ml) fails to run with Keras

我运行正在使用 Comet github project 中的 keras 示例。

我添加导入并创建一个新实验:

def train(x_train,y_train,x_test,y_test):
model = build_model_graph()

from comet_ml import Experiment

experiment = Experiment(api_key="XXXX", log_code=True)

model.fit(x_train, y_train, batch_size=128, epochs=50, validation_data=(x_test, y_test))

score = model.evaluate(x_test, y_test, verbose=0)

当我 运行 我的训练代码失败时。

错误:

Using TensorFlow backend.
Traceback (most recent call last):
  File "/Users/nimrodlahav/Code/semantica/experiment-logger-client/train-examples/keras-example.py", line 21, in <module>
    from comet_ml import Experiment
  File ".././comet-client-lib/comet_ml/__init__.py", line 3, in <module>
    from .comet import Experiment
  File ".././comet-client-lib/comet_ml/comet.py", line 29, in <module>
    from comet_ml import keras_logger
  File ".././comet-client-lib/comet_ml/keras_logger.py", line 31, in <module>
    raise SyntaxError("Please import Comet before importing any keras modules")
SyntaxError: Please import Comet before importing any keras modules

我错过了什么?

我没有看到代码的开头,但看起来您在导入 Comet 之前已经导入了 Keras。

从错误消息来看,似乎只需要切换导入线(Comet 首先是 Keras,其次),就像您的示例一样:

from comet_ml import Experiment

import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import RMSprop 

查看完整的源代码example