How to convert a pytorch script into tensorflow?

anshs: <p>I am trying to convert a pytorch script into tensorflow, how may I do so? Do we do it line by line or does the overall structure change in tensorflow?</p>
<p>Please, someone help me with this and provide some usefull link for this!</p>
<p>The code refers to graph convolution network. I see that pytorch_geometric has predefined modules like MessagePassing from which GCNConv is inheriting.</p>
<p>Is there any similar module in tensorflow?</p>
<p><strong>GCN Code:</strong></p>
<pre><code class="lang-auto">
</code></pre>
<pre><code class="lang-auto">import torch
from torch.nn import Parameter
from torch_scatter import scatter_add
from torch_geometric.nn import MessagePassing
from torch_geometric.utils import remove_self_loops, add_self_loops

from inits import glorot, zeros
import pdb

class GCNConv(MessagePassing):
</code></pre>
<pre><code class="lang-auto">def __init__(self,
             in_channels,
             out_channels,
             improved=False,
             cached=False,
             bias=True):
    super(GCNConv, self).__init__('add')

    self.in_channels = in_channels
    self.out_channels = out_channels
    self.improved = improved
    self.cached = cached
    self.cached_result = None

    self.weight = Parameter(torch.Tensor(in_channels, out_channels))

    if bias:
        self.bias = Parameter(torch.Tensor(out_channels))
    else:
        self.register_parameter('bias', None)

    self.reset_parameters()

def reset_parameters(self):
    glorot(self.weight)
    zeros(self.bias)
    self.cached_result = None


@staticmethod
def norm(edge_index, num_nodes, edge_weight, improved=False, dtype=None):
    if edge_weight is None:
        edge_weight = torch.ones((edge_index.size(1), ),
                                 dtype=dtype,
                                 device=edge_index.device)
    edge_weight = edge_weight.view(-1)
    assert edge_weight.size(0) == edge_index.size(1)

    edge_index, edge_weight = remove_self_loops(edge_index, edge_weight)
    edge_index, _ = add_self_loops(edge_index, num_nodes=num_nodes)
    loop_weight = torch.full((num_nodes, ),
                             1 if not improved else 2,
                             dtype=edge_weight.dtype,
                             device=edge_weight.device)
    edge_weight = torch.cat([edge_weight, loop_weight], dim=0)

    row, col = edge_index
    
    deg = scatter_add(edge_weight, col, dim=0, dim_size=num_nodes)
    deg_inv_sqrt = deg.pow(-1)
    deg_inv_sqrt[deg_inv_sqrt == float('inf')] = 0

    return edge_index, deg_inv_sqrt[col] * edge_weight


def forward(self, x, edge_index, edge_weight=None):
    """"""
    x = torch.matmul(x, self.weight)

    if not self.cached or self.cached_result is None:
        edge_index, norm = self.norm(edge_index, x.size(0), edge_weight,
                                     self.improved, x.dtype)
        self.cached_result = edge_index, norm
    edge_index, norm = self.cached_result

    return self.propagate(edge_index, x=x, norm=norm)


def message(self, x_j, norm):
    return norm.view(-1, 1) * x_j

def update(self, aggr_out):
    if self.bias is not None:
        aggr_out = aggr_out + self.bias
    return aggr_out

def __repr__(self):
    return '{}({}, {})'.format(self.__class__.__name__, self.in_channels,
                               self.out_channels)
</code></pre>
<pre><code class="lang-auto">
</code></pre>
<p>The script is of a graph convolutional network. (source: <a href="https://github.com/seongjunyun/Graph_Transformer_Networks" rel="noopener nofollow ugc">source code</a> )</p>

anshs: <p>Where may I post this in order to get some help?</p>

AlphaBetaGamma96: <aside class="onebox allowlistedgeneric" data-onebox-src="https://discuss.tensorflow.org/">
  <header class="source">
      <img src="https://discuss.tensorflow.org/uploads/default/optimized/1X/eb3557f596c0a9ea0870192b5a5ecedd99c4f1f4_2_32x32.png" class="site-icon" width="32" height="32">

      <a href="https://discuss.tensorflow.org/" target="_blank" rel="noopener nofollow ugc">TensorFlow Forum</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:560/500;"><img src="https://discuss.tensorflow.org/uploads/default/original/1X/3ab38b8b93680ec650c1a69f38a7fcab39fe809f.png" class="thumbnail" width="560" height="500"></div>

<h3><a href="https://discuss.tensorflow.org/" target="_blank" rel="noopener nofollow ugc">TensorFlow Forum</a></h3>

  <p>A discussion platform to foster constructive conversation and support between TensorFlow community members.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


anshs: <p>I have already posted there as well! Thanks for the suggestion!</p>