I got some errors about the types of the “tensor” that flow over the layers.
Finaly I had understood that this model have two types of outputs and I should choose the one i wanted, and when I choose the one I wanted the entire model works well.
On the other hand, I did some steps since opening this topic but I still got some prolems with building the exact model I wanted:
I should separate between the resnet101 and the deepLbv3, and when I try to do so I got a problem that the deeplabv3’s output size is too small, instead of the original image size.
I tryed to take the resnet101 by itself, and to reconstruct only the deeplabv3, and it seems that the sepapartion of the deeplabv3 model to children, and recombining them together changing the model.
this is the py file I tryed:
import torch
import urllib
from PIL import Image
from torchvision import transforms
import matplotlib.pyplot as plt
from model import deeplab_v3_separation
import torchvision.models as models

deepLabV3ResNet101 = models.segmentation.deeplabv3_resnet101(pretrained=True)
# features_convs_and_ASSP = list(deepLabV3ResNet101.children())
# deepLabV3ResNet101_test = torch.nn.Sequential(*features_convs_and_ASSP)
# deepLabV3ResNet101_test.eval() 
deepLabV3ResNet101.eval()

ResNet101 = models.resnet101(pretrained=True)
ResNet101_features = list(ResNet101.children())
ResNet101_test = torch.nn.Sequential(*ResNet101_features[:-2])
ResNet101_test.eval() 

ASSP_layers = models.segmentation.deeplabv3_resnet101(pretrained=True)
ASSP_features = list(ASSP_layers.children())
# ASSP_classifier = list(ASSP_layers.classifier.children())
ASSP_test = torch.nn.Sequential(*ASSP_features[1:2])
ASSP_test.eval() 

input_image = Image.open('a.jpg')
preprocess = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
input_tensor = preprocess(input_image)
input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model

# move the input and model to GPU for speed if available
if torch.cuda.is_available():
    input_batch = input_batch.to('cuda')
    ResNet101_test.to('cuda')
    ASSP_test.to('cuda')
    deepLabV3ResNet101.to('cuda')

with torch.no_grad():
    output = ResNet101_test(input_batch)
    output2 = ASSP_test(output)
    output3 = deepLabV3ResNet101(input_batch)

print(output.size())
print(output2.size())
print(output3['out'].size())

and this is the output (image size = 375, 500 ):
torch.Size([1, 2048, 12, 16])
torch.Size([1, 21, 12, 16])
torch.Size([1, 21, 375, 500])

thanks for help!