geffy / tffm

TensorFlow implementation of an arbitrary order Factorization Machine
MIT License
780 stars 176 forks source link

Restore a trained model #10

Closed Vimos closed 7 years ago

Vimos commented 8 years ago

I am trying to restore a model from saved state and got the error

Traceback (most recent call last):
  File "predict.py", line 116, in <module>
    df_predict[v] = predict_with(v)
  File "predict.py", line 95, in predict_with
    fm.load_state(model_file)
  File "/home/revenueml/git/revenueml/revenueml/tffm/base.py", line 300, in load_state
    self.core.build_graph()
  File "/home/revenueml/git/revenueml/revenueml/tffm/core.py", line 183, in build_graph
    assert self.n_features is not None
AssertionError

I fixed this with

    fm.core.set_num_features(fmap.index.size)

Hope this can help somebody else.

Please add some usage on restoring models in readme, this may be quite helpful.

geffy commented 7 years ago

Yes, it's true. For now, I don't know a good way to store graph and weights. So, I just added assertion message and usage example in example.ipynb