彗星(彗星-ml)无法与Keras一起跑

时间:2017-09-21 20:10:59

标签: python tensorflow keras comet comet-ml

我正在运行来自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

我错过了什么?

1 个答案:

答案 0 :(得分:2)

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

从错误消息中看起来只需要切换导入行(Comet first Keras second),就像在你的例子中一样:

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