Git Product home page Git Product logo

Comments (5)

MisaOgura avatar MisaOgura commented on May 22, 2024

Hi @vainaijr,

I would need more information in order to diagnose:

e.g. the model architecture, how you are instantiating the GradientAscent object etc,

Please also provide any other information you think would be useful.

Many thanks,
Misa

from flashtorch.

vainaixr avatar vainaixr commented on May 22, 2024

hello,
my model looks like this,

def conv_block(in_channels, out_channels, k):
    return nn.Sequential(
        nn.Conv2d(in_channels, in_channels, k, padding=0),
        nn.BatchNorm2d(in_channels),
        nn.ReLU(),
        nn.MaxPool2d(2)
    )

class Top(nn.Module):
  def __init__(self):
    super().__init__()
    self.encoder = conv_block(3, 3, 1)
    self.lin = nn.Linear(20, 10)
    self.childone = Second()
    self.childtwo = Second()
  def forward(self, x):
    # set_trace()
    a, b = self.childone(self.encoder(x)), self.childtwo(self.encoder(x))
    # print('top', a.shape, b.shape)
    out = torch.cat((a, b), dim=-1)
    return self.lin(out) 

class Second(nn.Module):
  def __init__(self):
    super().__init__()
    self.encoder = conv_block(3, 3, 1)
    self.lin = nn.Linear(20, 10)
    self.childone = Middle()
    self.childtwo = Middle()

  def forward(self, x):
    a, b = self.childone(self.encoder(x)), self.childtwo(self.encoder(x))
    # print('middle', a.shape, b.shape)
    out = torch.cat((a, b), dim=-1)
    return self.lin(out)

class Middle(nn.Module):
  def __init__(self):
    super().__init__()
    self.encoder = conv_block(3, 3, 1)
    self.lin = nn.Linear(20, 10)
    self.childone = Bottom()
    self.childtwo = Bottom()

  def forward(self, x):
    a, b = self.childone(self.encoder(x)), self.childtwo(self.encoder(x))
    # print('middle', a.shape, b.shape)
    out = torch.cat((a, b), dim=-1)
    return self.lin(out)

class Bottom(nn.Module):
  def __init__(self):
    super().__init__()
    self.encoder = conv_block(3, 3, 1)
    self.lin_one = nn.Linear(12, 10)
  def forward(self, x):
    # print('bottom', x.shape)
    out = self.encoder(x)
    return (self.lin_one(out.view(out.size(0), -1)))

model = Top()
model.to('cuda')
from flashtorch.activmax import GradientAscent
g_ascent = GradientAscent(model)
g_ascent.use_gpu = True

g_ascent.visualize(model.childtwo.childtwo.childtwo.encoder[0], title='conv');

I pass images from top neural network to second one, then to middle, then to bottom, and then get 10 probabilities, which I pass to the top.

I have to use flashtorch to visualize what each neural network learns, this is different from .deep learning where we have only one model, here I use multiple encoders, decoders, and pass output top to bottom, or bottom to top.

from flashtorch.

MisaOgura avatar MisaOgura commented on May 22, 2024

Thanks @vainaijr,

GradientAscent is fairly architecture-agnostic.

For certain types of architecture, especially if the liner layers are interwoven and hence can't be separated, you might have to set the img_size to what the model expects. The default is img_size=224.

You can do so by passing it in on the object instantiation or by reassigning the attribute.

I.e.

g_ascent = GradientAscent(model, img_size=int)

Or

g_ascent.img_size = int

Let me know how it goes.

Many thanks,
Misa

from flashtorch.

vainaixr avatar vainaixr commented on May 22, 2024

it started working, thanks
Screenshot (465)

from flashtorch.

MisaOgura avatar MisaOgura commented on May 22, 2024

That's great @vainaijr, looking forward to hearing what insights you gain with FlashTorch.

from flashtorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.