benedekrozemberczki / graph2vec

A parallel implementation of "graph2vec: Learning Distributed Representations of Graphs" (MLGWorkshop 2017).
https://karateclub.readthedocs.io/
GNU General Public License v3.0
901 stars 169 forks source link

AttributeError: 'DegreeView' object has no attribute 'items' #20

Closed Veritogen closed 4 years ago

Veritogen commented 4 years ago

Hey, I got a issue when trying to use only a edge list as input. I attached one of my files. The error is the following

python graph2vec/src/graph2vec.py --input-path graph_data/edge_lists/1/ --output-path nci2.csv

Feature extraction started.

100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00,  9.73it/s]
joblib.externals.loky.process_executor._RemoteTraceback: 
"""
Traceback (most recent call last):
  File "*/venv/lib/python3.8/site-packages/joblib/externals/loky/process_executor.py", line 418, in _process_worker
    r = call_item()
  File "*/venv/lib/python3.8/site-packages/joblib/externals/loky/process_executor.py", line 272, in __call__
    return self.fn(*self.args, **self.kwargs)
  File "*/venv/lib/python3.8/site-packages/joblib/_parallel_backends.py", line 608, in __call__
    return self.func(*args, **kwargs)
  File "*/venv/lib/python3.8/site-packages/joblib/parallel.py", line 255, in __call__
    return [func(*args, **kwargs)
  File "*/venv/lib/python3.8/site-packages/joblib/parallel.py", line 255, in <listcomp>
    return [func(*args, **kwargs)
  File "graph2vec/src/graph2vec.py", line 82, in feature_extractor
    graph, features, name = dataset_reader(path)
  File "graph2vec/src/graph2vec.py", line 72, in dataset_reader
    features = {int(k): v for k, v in features.items()}
AttributeError: 'DegreeView' object has no attribute 'items'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "graph2vec/src/graph2vec.py", line 129, in <module>
    main(args)
  File "graph2vec/src/graph2vec.py", line 112, in main
    document_collections = Parallel(n_jobs=args.workers)(delayed(feature_extractor)(g, args.wl_iterations) for g in tqdm(graphs))
  File "*/venv/lib/python3.8/site-packages/joblib/parallel.py", line 1017, in __call__
    self.retrieve()
  File "*/venv/lib/python3.8/site-packages/joblib/parallel.py", line 909, in retrieve
    self._output.extend(job.get(timeout=self.timeout))
  File "*/venv/lib/python3.8/site-packages/joblib/_parallel_backends.py", line 562, in wrap_future_result
    return future.result(timeout=timeout)
  File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
AttributeError: 'DegreeView' object has no attribute 'items'

I managed to solve it by editing the function dataset_reader:

def dataset_reader(path):
    """
    Function to read the graph and features from a json file.
    :param path: The path to the graph json.
    :return graph: The graph object.
    :return features: Features hash table.
    :return name: Name of the graph.
    """
    name = path.strip(".json").split("/")[-1]
    data = json.load(open(path))
    graph = nx.from_edgelist(data["edges"])

    if "features" in data.keys():
        features = data["features"]
        # moved the following line up because it wont work for the features derived by nx.degree()
        features = {int(k): v for k, v in features.items()}
    else:
        features = nx.degree(graph)
        # added this line features is a list of tuples
        features = {int(feature[0]): feature[1] for feature in features}
    return graph, features, name

I hope it does what the function was supposed to be. I attached one of my files as example below. 805431435.zip

benedekrozemberczki commented 4 years ago

Could you open a PR?