Accenture / AmpliGraph

Python library for Representation Learning on Knowledge Graphs https://docs.ampligraph.org
Apache License 2.0
2.16k stars 250 forks source link

Error with Tensorflow >=1.14 #191

Closed mhmgad closed 4 years ago

mhmgad commented 4 years ago

Description

Unable to use the ampligraph 1.3 with Tensorflow 1.4 as recommended in the readme file Module model_utils imports tensorflow projector from a deprecated location from tensorflow.contrib.tensorboard.plugins import projector

Actual Behavior

Traceback (most recent call last):
  File "/home/gadelrab/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/gadelrab/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/gadelrab/ExDEC/experiments/run_experiments.py", line 7, in <module>
    from cli.main import initiate_problem, get_parser
  File "/home/gadelrab/ExDEC/cli/main.py", line 1, in <module>
    from ampligraph.latent_features import set_entity_threshold
  File "/home/gadelrab/anaconda3/lib/python3.7/site-packages/ampligraph/latent_features/__init__.py", line 32, in <module>
    from ..utils import save_model, restore_model
  File "/home/gadelrab/anaconda3/lib/python3.7/site-packages/ampligraph/utils/__init__.py", line 12, in <module>
    from .model_utils import save_model, restore_model, create_tensorboard_visualizations, \
  File "/home/gadelrab/anaconda3/lib/python3.7/site-packages/ampligraph/utils/model_utils.py", line 16, in <module>
    from tensorflow.contrib.tensorboard.plugins import projector
ModuleNotFoundError: No module named 'tensorflow.contrib'

Would you issue any quick fix for this error the library is not usable? Add to that using Tensorflow 1.3 produces many warning.

lukostaz commented 4 years ago

Hello @mhmgad, Note installation guide suggests minimum tf version is 1.14.0. TF version 1.4 is not supported.

Tried this on my end and it works OK: Can you please double-check on your side? Which tf version are you on?

import tensorflow as tf
print(tf.version.VERSION)
1.14.0
import ampligraph
ampligraph.__version__
'1.3.0'
import numpy as np
from ampligraph.latent_features import TransE
from ampligraph.utils import create_tensorboard_visualizations

X = np.array([['a', 'y', 'b'],
              ['b', 'y', 'a'],
              ['a', 'y', 'c'],
              ['c', 'y', 'a'],
              ['a', 'y', 'd'],
              ['c', 'y', 'd'],
              ['b', 'y', 'c'],
              ['f', 'y', 'e']])
model = TransE(batches_count=1, seed=555, epochs=20, k=10, loss='pairwise',
               loss_params={'margin':5})
model.fit(X)
WARNING - All triples will be processed in the same batch (batches_count=1). When processing large graphs it is recommended to batch the input knowledge graph instead.
create_tensorboard_visualizations(model, 'tensorboard_files')
mhmgad commented 4 years ago

Thank you @lukostaz for the quick response. First 1.4 was a mistake it is 1.14

So, I found out that I have a conflict in the environment packages between conda and pip. pip was listing tensorflow 2.0 while conda showing 1.15 or 1.14. I created a clean environment and made sure that there is no tensorflow installed on the pip list and installed using conda, it works fine.

Thank you for your time, and sorry for the inconvenience.

lukostaz commented 4 years ago

No problem at all, glad you sorted that out.