kazuto1011 / deeplab-pytorch

PyTorch re-implementation of DeepLab v2 on COCO-Stuff / PASCAL VOC datasets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extract Feature map

achreff opened this issue · comments

Hi,
Thank you for the code.
I have a question please. You architecture is based encoder-decoder. In the end of the encoder we fin the feature map that contains the image description. from your code from anywhere i can extracted it ?

thank you

This is an example of my DeepLab v2. DeepLab v3/v3+ can also be done in the same manner, but the pretrained weights do not exist for them.

import torch
import torch.hub

from libs.models.deeplabv2 import DeepLabV2


# define a custom forward
class Extractor(DeepLabV2):
    def forward(self, x):
        h = self.layer1(x)
        h = self.layer2(h)
        h = self.layer3(h)
        h = self.layer4(h)
        h = self.layer5(h)
        # skip the last layer, self.aspp
        return h


weights = torch.hub.load(
    "kazuto1011/deeplab-pytorch",
    "deeplabv2_resnet101",
    pretrained="cocostuff164k",
    n_classes=182,
).base.state_dict()

f = Extractor(n_classes=182, n_blocks=[3, 4, 23, 3], atrous_rates=[6, 12, 18, 24])
f.load_state_dict(weights)
x = torch.randn(1, 3, 513, 513)
y = f(x)  # returns (1, 1024, 65, 65)

Thank you for reply :) is very helpful