# Tutorial on Graph Neural Networks for Computer Vision and Beyond (Part 1)

Aug 4 · 16 min read

In many practical cases, it is actually you who gets to decide what are the nodes and edges in a graph.

# 2. Why is it difficult to define convolution on graphs?

## 2.1. Why is convolution useful?

Ideally, our goal is to develop a model that is as flexible as Graph Neural Nets and can digest and learn from any data, but at the same time we want to control (regularize) factors of this flexibility by turning on/off certain priors.

## 2.2. Convolution on images in terms of graphs

Nodes are a set, and any permutation of this set does not change it. Therefore, the aggregator operator that people apply should be permutation-invariant.

# 3. What makes a neural network a graph neural network?

`import numpy as npfrom scipy.spatial.distance import cdistimg_size = 28  # MNIST image width and heightcol, row = np.meshgrid(np.arange(img_size), np.arange(img_size))coord = np.stack((col, row), axis=2).reshape(-1, 2) / img_sizedist = cdist(coord, coord)  # see figure below on the leftsigma = 0.2 * np.pi  # width of a GaussianA = np.exp(- dist / sigma ** 2)  # see figure below in the middle`
`import torch.nn as nn  # using PyTorchnn.Sequential(nn.Linear(4, 64),  # map coordinates to a hidden layer              nn.ReLU(),         # nonlinearity              nn.Linear(64, 1),  # map hidden representation to edge              nn.Tanh())         # squash edge values to [-1, 1]`

To make GNNs work better on regular graphs, like images, we need to apply a bunch of tricks. For example, instead of using a predefined Gaussian filter, we can learn to predict an edge between any pair of pixels.

# Conclusion

Written by

## Boris Knyazev

#### PhD student at University of Guelph

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just \$5/month. Upgrade