{"id":13444174,"url":"https://github.com/Tixierae/graph_2D_CNN","last_synced_at":"2025-03-20T18:31:19.751Z","repository":{"id":74422364,"uuid":"98657591","full_name":"Tixierae/graph_2D_CNN","owner":"Tixierae","description":"Code and data for the paper 'Classifying Graphs as Images with Convolutional Neural Networks' (new title: 'Graph Classification with 2D Convolutional Neural Networks')","archived":false,"fork":false,"pushed_at":"2019-12-13T08:46:13.000Z","size":1685,"stargazers_count":77,"open_issues_count":1,"forks_count":25,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-28T08:39:36.457Z","etag":null,"topics":["2d-cnn","artificial-intelligence","classification","convolutional-neural-networks","deep-learning","embeddings","graph-2d-cnn","graph-kernels","graph-theory","keras","neural-networks","representation-learning","tensorflow"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/1708.02218","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tixierae.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-07-28T14:29:49.000Z","updated_at":"2024-09-03T15:07:34.000Z","dependencies_parsed_at":"2024-01-17T16:08:26.476Z","dependency_job_id":"ec9b372d-2543-4885-93c9-f0d0f295cd2a","html_url":"https://github.com/Tixierae/graph_2D_CNN","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tixierae%2Fgraph_2D_CNN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tixierae%2Fgraph_2D_CNN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tixierae%2Fgraph_2D_CNN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tixierae%2Fgraph_2D_CNN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tixierae","download_url":"https://codeload.github.com/Tixierae/graph_2D_CNN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244670109,"owners_count":20490919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d-cnn","artificial-intelligence","classification","convolutional-neural-networks","deep-learning","embeddings","graph-2d-cnn","graph-kernels","graph-theory","keras","neural-networks","representation-learning","tensorflow"],"created_at":"2024-07-31T03:02:20.925Z","updated_at":"2025-03-20T18:31:19.132Z","avatar_url":"https://github.com/Tixierae.png","language":"Python","funding_links":[],"categories":["Python","Deep Learning"],"sub_categories":[],"readme":"# Graph classification with 2D CNNs ![GitHub stars](https://img.shields.io/github/stars/tixierae/graph_2D_CNN.svg?style=plastic) ![GitHub forks](https://img.shields.io/github/forks/tixierae/graph_2D_CNN.svg?color=blue\u0026style=plastic)\n\n[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/graph-classification-with-2d-convolutional/graph-classification-on-collab)](https://paperswithcode.com/sota/graph-classification-on-collab?p=graph-classification-with-2d-convolutional) [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/graph-classification-with-2d-convolutional/graph-classification-on-re-m12k)](https://paperswithcode.com/sota/graph-classification-on-re-m12k?p=graph-classification-with-2d-convolutional) [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/graph-classification-with-2d-convolutional/graph-classification-on-re-m5k)](https://paperswithcode.com/sota/graph-classification-on-re-m5k?p=graph-classification-with-2d-convolutional) [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/graph-classification-with-2d-convolutional/graph-classification-on-imdb-b)](https://paperswithcode.com/sota/graph-classification-on-imdb-b?p=graph-classification-with-2d-convolutional)\n\n### What is this repo for?\nThis repo provides the code and datasets used in the paper [Classifying graphs as images with Convolutional Neural Networks](https://arxiv.org/abs/1708.02218) (Tixier, Nikolentzos, Meladianos and Vazirgiannis, 2017). Note that the paper was published at the ICANN 2019 conference under the title *Graph classification with 2D convolutional neural networks*. As its name suggests, the paper introduces a technique to perform graph classification with standard Convolutional Neural Networks for images (2D CNNs).\n\n### Idea\nWe encode graphs as stacks of 2D histograms of their node embeddings, and pass them to a classical 2D CNN architecture designed for images. The *bins* of the histograms can be viewed as *pixels*, and the value of a given pixel is the number of nodes falling into the associated bin.\n\nFor instance, below are the node embeddings and corresponding bivariate histograms for graph ID #10001 (577 nodes, 1320 edges) of the REDDIT-12K dataset:\n![alt text](https://github.com/Tixierae/graph_2D_CNN/raw/master/image_example_graph_cnn_github.png)\nThe full image representation of a graph is given by stacking its n_channels bivariate histograms (where n_channels can be 2,5...). Each pixel is thus associated with a n_channels-dimensional vector of counts.\n\n### Results\nDespite its simplicity, our method proves very competitive to state-of-the-art graph kernels, and even outperforms them by a wide margin on some datasets. \n\n10-fold CV average test set classification accuracy of state-of-the-art graph kernel and graph CNN baselines (top), vs our 2D CNN approach (bottom):\n![alt text](https://github.com/Tixierae/graph_2D_CNN/raw/master/results_graph_cnn_github.png)\n\nThe results reported in the paper (without data augmentation) are available in the `/datasets/results/` subdirectory, with slight variations due to the stochasticity of the approach. You can read them using the `read_results.py` script.\n\n### Advantages over graph kernels + SVM (GK+SVM)\nWe can summarize the advantages of our approach as follows:\n* **better accuracy**: CNNs learn their own features directly from the raw data during training to optimize performance on the downstream task (whereas GKs compute similarity *a priori*)\n* **better accuracy**: we compute images of graphs from their node embeddings (obtained via node2vec), so we capture both *local* and *global* information about the networks (whereas most GKs, based on substructures, capture only local information)\n* **reduced time complexity at the graph level**: node2vec is linear in the number of nodes (whereas most GKs are polynomial) -\u003e we can process bigger graphs\n* **reduced time complexity at the collection level**: the time required to process a graph with a 2D CNN is constant (all images have same dimension for a given dataset), and the time required to go through the entire dataset with a 2D CNN grows linearly with the size of the dataset (whereas GKs take quadratic time to compute kernel matrix, then finding the support vectors is again quadratic) -\u003e we can process bigger datasets\n\n\n### Use\n* `get_node2vec.py` computes the node2vec embeddings of the graphs from their adjacency matrices (parallelized over graphs)\n* `get_histograms.py` computes the image representations of the graphs (stacks of 2D histograms) from their node2vec embeddings (parallelized over graphs)\n* `main.py` reproduces the experiments in the paper (classification of graphs as images with a 2D CNN architecture, using a 10-fold cross validation scheme)\n* `main_data_augmentation.py` is like `main.py`, but it implements the data augmentation scheme described in the paper (smoothed bootstrap)\n\nCommand line examples and descriptions of the parameters are available within each script.\n\n### Setup \nCode was developed and tested under Ubuntu 16.04.2 LTS 64-bit operating system and Python 2.7 with [Keras 1.2.2](https://faroit.github.io/keras-docs/1.2.2/) and tensorflow 1.1.0 backend.\n\n### Other notable dependencies\n* igraph 0.7.1\n* scikit-learn 0.18.1\n* numpy 1.11.0\n* multiprocessing\n* functools\n* json\n* argparse\n\n### Correspondence between names of datasets in the paper and in the code (paper -\u003e code)\n* IMDB-B -\u003e imdb_action_romance\n* COLLAB -\u003e collab\n* REDDIT-B -\u003e reddit_iama_askreddit_atheism_trollx\n* REDDIT-5K -\u003e reddit_multi_5K\n* REDDIT-12K -\u003e reddit_subreddit_10K\n\n### Cite\nIf you use some of the code in this repository in your work, please cite:\n\nConference version (ICANN 2019):\n````BibTeX\n@inproceedings{tixier2019graph,\n  title={Graph classification with 2d convolutional neural networks},\n  author={Tixier, Antoine J-P and Nikolentzos, Giannis and Meladianos, Polykarpos and Vazirgiannis, Michalis},\n  booktitle={International Conference on Artificial Neural Networks},\n  pages={578--593},\n  year={2019},\n  organization={Springer}\n}\n````\n\nPre-print version (2017):\n````BibTeX\n@article{tixier2017classifying,\n  title={Classifying Graphs as Images with Convolutional Neural Networks},\n  author={Tixier, Antoine Jean-Pierre and Nikolentzos, Giannis and Meladianos, Polykarpos and Vazirgiannis, Michalis},\n  journal={arXiv preprint arXiv:1708.02218},\n  year={2017}\n}\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTixierae%2Fgraph_2D_CNN","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTixierae%2Fgraph_2D_CNN","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTixierae%2Fgraph_2D_CNN/lists"}