matej-ulicny / harmonic-networks

BSD 3-Clause "New" or "Revised" License
57 stars 7 forks source link

How to change the input size of the network? #1

Closed ma3252788 closed 4 years ago

ma3252788 commented 4 years ago

There are 8 categories in my dataset. The input is 224. Can you tell me what should be modified? Thank you very much.

matej-ulicny commented 4 years ago

If you have your own model you want to use and you just want to replace the layers you can substitute all the Conv2d classes with Harm2d in your code.

If you wish to train or finetune one of the models provided, you can create it this way (pretrained ResNet50 example):

model = models.resnet50(pretrained=True, harm_root=True, harm_res_blocks=True)
model.fc = nn.Linear(model.fc.in_features, 8)
ma3252788 commented 4 years ago

If you have your own model you want to use and you just want to replace the layers you can substitute all the Conv2d classes with Harm2d in your code.

If you wish to train or finetune one of the models provided, you can create it this way (pretrained ResNet50 example):

model = models.resnet50(pretrained=True, harm_root=True, harm_res_blocks=True)
model.fc = nn.Linear(model.fc.in_channels, 8)

@matej-ulicny Thanks for your reply!! I tested tv_resnet50 according to what you said, but during the training, an error occurred: AttributeError: 'Linear' object has no attribute 'in_channels'

ma3252788 commented 4 years ago

Then, I tested resnet 18 again. I set pretrained to True and changed "in channels" to "in chans". The training can continue, but it doesn't seem to load the pretraining model. I didn't even find that it automatically downloads the pretraining model.

image

ma3252788 commented 4 years ago

After I output the model, I checked it. I think you are talking about in_features?

image

But when I started training, there was no prompt in my terminal whether the pre training model was loaded. How do I know if the pre training model is loaded?

matej-ulicny commented 4 years ago

You are correct, it should be model.fc.in_features.

Only models you can see in this release are pre-trained: https://github.com/matej-ulicny/harmonic-networks/releases

resnet50, resnet101 and vgg16_bn are defined in: https://github.com/matej-ulicny/harmonic-networks/tree/master/imagenet/models

and within the resnext folder we have pretrained only:

ma3252788 commented 4 years ago

You are correct, it should be model.fc.in_features.

Only models you can see in this release are pre-trained: https://github.com/matej-ulicny/harmonic-networks/releases

resnet50, resnet101 and vgg16_bn are defined in: https://github.com/matej-ulicny/harmonic-networks/tree/master/imagenet/models

and within the resnext folder we have pretrained only:

  • se_resnext101_32x4d
  • harm_se_resnext101_32x4d
  • harm_se_resnext101_64x4d

Thank you very much! That's great. Pre-training really helps.