neuralchen / SimSwap

An arbitrary face-swapping framework on images and videos with one single trained model!
Other
4.51k stars 890 forks source link

Will the test code be updated to properly work with own 512 and 224 pretrained models? #261

Open netrunner-exe opened 2 years ago

boreas-l commented 2 years ago

I find:
1、in train.py and test_wholeimage_swapsingle.py, the initial network was not the same...
in train.py:

from models.projected_model import fsModel  
# model initial  
model = fsModel()  
# fsModel() source from **projected_model.py**, and in that, the Generator_Adain_Upsample source from fs_networks_fix

and in test_wholeimage_swapsingle.py:

from models.models import create_model  
# model initial
model = create_model(opt)  
# fsModel() source from fs_model.py, and in that, the Generator_Adain_Upsample source from fs_networks_512  

in general, the Generator_Adain_Upsample is diffenent between train.py and test_wholeimage_swapsingle.py.

2、so, after train, in your own pretrained_weight, you need initial network like train.py instead of test_wholeimage_swapsingle.py.

# test.py  
from models.projected_model import fsModel  

model = fsModel()  
# remenber add Gdeep=True in TestOptions 
model.initialize(opt)  
model.netG.eval()  

# and data preprocess like train.py
def data_preprocess(img):  
    img_tensor = transforms.ToTensor()(img)  
    img_tensor = img_tensor.view(-1, 3, img.size[0], img.size[1])  
    mean = torch.tensor([0.485, 0.456, 0.406]).cuda().view(1, 3, 1, 1)  
    std = torch.tensor([0.229, 0.224, 0.225]).cuda().view(1, 3, 1, 1)  
    img_tensor = img_tensor.cuda(non_blocking=True)  
    img_tensor = img_tensor.sub_(mean)._div(std)  
    return img_tensor  
YaoQ commented 2 years ago

The preprocess and the postprocess part for own trained model are different the inference demo code, and you have to update the demo code according to train.py

netrunner-exe commented 2 years ago

I find: 1、in train.py and test_wholeimage_swapsingle.py, the initial network was not the same... in train.py:

from models.projected_model import fsModel  
# model initial  
model = fsModel()  
# fsModel() source from **projected_model.py**, and in that, the Generator_Adain_Upsample source from fs_networks_fix

and in test_wholeimage_swapsingle.py:

from models.models import create_model  
# model initial
model = create_model(opt)  
# fsModel() source from fs_model.py, and in that, the Generator_Adain_Upsample source from fs_networks_512  

in general, the Generator_Adain_Upsample is diffenent between train.py and test_wholeimage_swapsingle.py.

2、so, after train, in your own pretrained_weight, you need initial network like train.py instead of test_wholeimage_swapsingle.py.

# test.py  
from models.projected_model import fsModel  

model = fsModel()  
# remenber add Gdeep=True in TestOptions 
model.initialize(opt)  
model.netG.eval()  

# and data preprocess like train.py
def data_preprocess(img):  
    img_tensor = transforms.ToTensor()(img)  
    img_tensor = img_tensor.view(-1, 3, img.size[0], img.size[1])  
    mean = torch.tensor([0.485, 0.456, 0.406]).cuda().view(1, 3, 1, 1)  
    std = torch.tensor([0.229, 0.224, 0.225]).cuda().view(1, 3, 1, 1)  
    img_tensor = img_tensor.cuda(non_blocking=True)  
    img_tensor = img_tensor.sub_(mean)._div(std)  
    return img_tensor  

Thank you very much! I tried to make changes but got errors. But still, the fact that at least someone managed to run the test code pleases me. Otherwise, what is the point of training if it is impossible to fully run the test code with own model? Just because it's been asked for so long? Let's wait and hope that the developer will fix the test code and give us the opportunity to run all test code with old models and with our own pretrained models as it should be.

netrunner-exe commented 2 years ago

I find: 1、in train.py and test_wholeimage_swapsingle.py, the initial network was not the same... in train.py:

from models.projected_model import fsModel  
# model initial  
model = fsModel()  
# fsModel() source from **projected_model.py**, and in that, the Generator_Adain_Upsample source from fs_networks_fix

and in test_wholeimage_swapsingle.py:

from models.models import create_model  
# model initial
model = create_model(opt)  
# fsModel() source from fs_model.py, and in that, the Generator_Adain_Upsample source from fs_networks_512  

in general, the Generator_Adain_Upsample is diffenent between train.py and test_wholeimage_swapsingle.py.

2、so, after train, in your own pretrained_weight, you need initial network like train.py instead of test_wholeimage_swapsingle.py.

# test.py  
from models.projected_model import fsModel  

model = fsModel()  
# remenber add Gdeep=True in TestOptions 
model.initialize(opt)  
model.netG.eval()  

# and data preprocess like train.py
def data_preprocess(img):  
    img_tensor = transforms.ToTensor()(img)  
    img_tensor = img_tensor.view(-1, 3, img.size[0], img.size[1])  
    mean = torch.tensor([0.485, 0.456, 0.406]).cuda().view(1, 3, 1, 1)  
    std = torch.tensor([0.229, 0.224, 0.225]).cuda().view(1, 3, 1, 1)  
    img_tensor = img_tensor.cuda(non_blocking=True)  
    img_tensor = img_tensor.sub_(mean)._div(std)  
    return img_tensor  

Can you provide full working with own pretrained 512 model example of test_wholeimage_swapsingle.py or manual on what and where to change or add?

boreas-l commented 2 years ago

so glad, can you provide your email? or another way?

netrunner-exe commented 2 years ago

so glad, can you provide your email? or another way?

netrunner.exe@gmail.com @boreas-l

netrunner-exe commented 2 years ago

so glad, can you provide your email? or another way?

That would be great, looking forward to it!

BeaverInGreenland commented 2 years ago

According to what is said here, how should we modify the arguments to make an inference on our own pretrained models ?

netrunner-exe commented 2 years ago

According to what is said here, how should we modify the arguments to make an inference on our own pretrained models ?

Hah, in usage doesn't writed anything about how to use own pretrained models. Currently, the test code is incompatible with published training code and own pretrained models...Do not waste your time and resources - there is no point in training, since you will not be able to use your model in any way:) Therefore, we are waiting for the announced SimSwap ++, maybe we will have more luck with it :)