Comments (5)
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.
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.
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.
from flashtorch.
That's great @vainaijr, looking forward to hearing what insights you gain with FlashTorch.
from flashtorch.
Related Issues (20)
- python2 or python3? HOT 1
- NOT WORKING FOR CONV3D HOT 1
- Custom Pytorch Model error HOT 2
- [BUG] Backprop.calculate_gradients gives rise to " AttributeError: 'NoneType' object has no attribute 'shape' " error HOT 3
- How can I use FlashTorch to see what the EfficientNet learn? HOT 1
- How to handle multi label multiclass? HOT 3
- [REQUEST] HOT 3
- Can I use my own model? HOT 3
- 3D images HOT 1
- use of custom model throws an error HOT 2
- [REQUEST]Support torch detection model?
- When I test my demo.jpg[BUG]
- [BUG] Colab demo for saliency maps: Gradient images are blank HOT 2
- Google Colab version not running [BUG] HOT 7
- Backprop is not working HOT 1
- RuntimeError HOT 2
- [REQUEST] calculate gradients for customized inputs
- Saliency map for a group of images
- [BUG]
- [Q] Does this support Vision Transformers (ViT)?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flashtorch.