error tensorboard add_graph with multiple input

By | March 10, 2024
Print Friendly, PDF & Email
885 Views

error tensorboard add_graph with multiple input  –  Biasanya untuk visualisasi model menggunakan tensorboard cukup mudah dan rata-rata contohnya hanya menggunakan single input

https://pytorch.org/tutorials/intermediate/tensorboard_tutorial.html dan hasilnya ok2 saja tanpa ada masalah. Namun ada kasus dimana terkadang kita membutuhkan banyak input alias multiple input pada contoh berikut hasilnya error.

# -*- coding: utf-8 -*-
"""
Created on Sun Mar 10 12:28:54 2024

@author: User
"""

import torch
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
from torch.autograd import Variable
# from tensorboardX import SummaryWriter
from torch.utils.tensorboard import SummaryWriter

class RNN(nn.Module):
    def __init__(self, input_size, hidden_size, output_size):
        super(RNN, self).__init__()
        self.hidden_size = hidden_size
        self.i2h = nn.Linear(
            input_size,
            hidden_size)
        self.i2o = nn.Linear(
            hidden_size,
            output_size)
        self.o2o = nn.Linear(hidden_size + output_size, output_size)
        self.dropout = nn.Dropout(0.1)
        self.softmax = nn.LogSoftmax(dim=1)

    def forward(self, input, hidden):
        hidden = self.i2h(input)
        output = self.i2o(hidden)
        output_combined = torch.cat((hidden, output), 1)
        output = self.o2o(output_combined)
        output = self.dropout(output)
        output = self.softmax(output)
        return output, hidden

    def initHidden(self):
        return torch.zeros(1, self.hidden_size)


n_letters = 100
n_hidden = 128
n_categories = 10
rnn = RNN(n_letters, n_hidden, n_categories)
cat = torch.Tensor(1, n_categories)
dummy_input = torch.Tensor(1, n_letters)
hidden = torch.Tensor(1, n_hidden)

out, hidden = rnn(dummy_input, hidden)
writer = SummaryWriter('runs/fashion_mnist_experiment_2')
writer.add_graph(rnn, (dummy_input, hidden), verbose=True)

ntah kenapa, sudah mengujungi forum-forum pun hasilnya nihil, juga sudah menggunakan tensorboardX juga

https://github.com/lanpa/tensorboardX/blob/master/examples/demo_graph.py

pun hasilnya juga sama. Berikut ketika menggunakan tensorboardX, hasilnya error juga

from tensorboardX import SummaryWriter
import torch.nn as nn
class MultipleInput(nn.Module):
    def __init__(self):
        super(MultipleInput, self).__init__()
        self.Linear_1 = nn.Linear(3, 5)


    def forward(self, x, y):
        return self.Linear_1(x+y)

with SummaryWriter(comment='MultipleInput') as w:
    w.add_graph(MultipleInput(), (torch.zeros(1, 3), torch.zeros(1, 3)), True)

hasilnya

w.add_graph(MultipleInput(), (torch.zeros(1, 3), torch.zeros(1, 3)), True)
graph(%self.1 : __torch__.MultipleInput,
      %x : Float(1, 3, strides=[3, 1], requires_grad=0, device=cpu),
      %y : Float(1, 3, strides=[3, 1], requires_grad=0, device=cpu)):
  %Linear_1 : __torch__.torch.nn.modules.linear.___torch_mangle_91.Linear = prim::GetAttr[name="Linear_1"](%self.1)
  %10 : int = prim::Constant[value=1]() # C:\Users\User\AppData\Local\Temp\ipykernel_22440\1404996206.py:8:0
  %input : Float(1, 3, strides=[3, 1], requires_grad=0, device=cpu) = aten::add(%x, %y, %10) # C:\Users\User\AppData\Local\Temp\ipykernel_22440\1404996206.py:8:0
  %bias : Tensor = prim::GetAttr[name="bias"](%Linear_1)
  %weight : Tensor = prim::GetAttr[name="weight"](%Linear_1)
  %21 : Float(1, 5, strides=[5, 1], requires_grad=1, device=cpu) = aten::linear(%input, %weight, %bias), scope: __module.Linear_1 # C:\ProgramData\Anaconda3\Lib\site-packages\torch\nn\modules\linear.py:116:0
  return (%21)


error tensorboard add_graph with multiple input belum tahu caranya!

See also  Hasil Training Pytorch Backend MPS GPU M1 tidak akurat dan solusinya

Leave a Reply