need some help in customizing timm efficient net model #1280
Unanswered
sparshgarg23
asked this question in
General
Replies: 3 comments 8 replies
-
@sparshgarg23 without looking in too much detail at all of the issues, you appear to have a typo and are using 'classifer' somewhere for the 'classifier' so that you end up with two classifiers, should try to fix that first... |
Beta Was this translation helpful? Give feedback.
2 replies
-
import timm
import torch
import torch.nn as nn
class AMT_Model(nn.Module):
def __init__(self):
super(AMT_Model,self).__init__()
self.model=timm.create_model('tf_efficientnet_b3_ns',pretrained=True)
for param in self.model.parameters():
param.requires_grad=False
self.model.classifier=nn.Sequential(
nn.Linear(in_features=1536,out_features=3)
)
def forward(self,x):
out=self.model(x)
return out
def build_model():
model=AMT_Model()
return model |
Beta Was this translation helpful? Give feedback.
2 replies
-
No, nn.Identity() just passes the output through with no overhead, it's
just there to avoid excessive conditionals when classifier is removed....
…On Fri, May 27, 2022 at 11:21 AM sparshgarg23 ***@***.***> wrote:
I tried printing the model summary using your wrapper.It seems that there
are two classifiers one is Idenityt and the other is the custom one defined.
(conv_head): Conv2d(384, 1536, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn2): BatchNorm2d(1536, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
(act2): SiLU(inplace=True)
(global_pool): SelectAdaptivePool2d (pool_type=avg, flatten=Flatten(start_dim=1, end_dim=-1))
(classifier): Identity()
)
(classifier): Sequential(
(0): Linear(in_features=1536, out_features=3, bias=True)
)
)
Wont't the two classifers be a problem.
—
Reply to this email directly, view it on GitHub
<#1280 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLQICBNWNCUXMLIKLY6YU3VMEHDDANCNFSM5XEEG2JA>
.
You are receiving this because you were mentioned.Message ID:
<rwightman/pytorch-image-models/repo-discussions/1280/comments/2836055@
github.com>
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was working with timm efficient net family and have the following implementations
I am able to train this model on my dataset and can easily make changes in it by simply removing the layers in classifier
However when I tried to put the same implementation in class as shown below
model summary for this new model is as follows
So why are there two classifiers and what changes should I make in the class so that my custom classifier is used
I also tried just extracting the features from the model and later on passing them to classifier
For this the class implementation is as follows
But this ends up giving the error
Where model summary is
I made one more change in the model as shown below
This ends up giving me the following error
This is strange because when on using the code shown in the first block i don't up getting the same error.
Also the model summary seems to be missing some stages as shown below
Would appreciate it if someone could point my mistakes and give me some suggestions on correcting them.
So what changes can be made into AMT_Model to ensure that the model summary looks like the one shown in the first code block.
Basically in my class I am trying to extract the features from timm efficient net and then pass them to the classifier.
Beta Was this translation helpful? Give feedback.
All reactions