AttributeError EfficientNet object has no attribute act1 same error every time any one know how to solve it ?? #307

Closed
opened 2022-07-27 03:25:30 +02:00 by 1YasserAmmar1 · 8 comments
1YasserAmmar1 commented 2022-07-27 03:25:30 +02:00 (Migrated from github.com)

L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.parallel.data_parallel.DataParallel' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.activation.PReLU' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.MaxPool2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.AdaptiveAvgPool2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.linear.Linear' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.activation.Sigmoid' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.dropout.Dropout' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm1d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
Traceback (most recent call last):
File "C:\Users\spn\Fake\SimSwap\train.py", line 139, in
model.initialize(opt)
File "C:\Users\spn\Fake\SimSwap\models\projected_model.py", line 57, in initialize
self.netD = ProjectedDiscriminator(diffaug=False, interp224=False, **{})
File "C:\Users\spn\Fake\SimSwap\pg_modules\projected_discriminator.py", line 161, in init
self.feature_network = F_RandomProj(**backbone_kwargs)
File "C:\Users\spn\Fake\SimSwap\pg_modules\projector.py", line 108, in init
self.pretrained, self.scratch = _make_projector(im_res=im_res, cout=self.cout, proj_type=self.proj_type, expand=self.expand)
File "C:\Users\spn\Fake\SimSwap\pg_modules\projector.py", line 64, in _make_projector
pretrained = _make_efficientnet(model)
File "C:\Users\spn\Fake\SimSwap\pg_modules\projector.py", line 35, in _make_efficientnet
pretrained.layer0 = nn.Sequential(model.conv_stem, model.bn1, model.act1, *model.blocks[0:2])
File "L:\spn\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1207, in getattr
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'EfficientNet' object has no attribute 'act1'

L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.parallel.data_parallel.DataParallel' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.activation.PReLU' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.MaxPool2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.AdaptiveAvgPool2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.linear.Linear' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.activation.Sigmoid' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.dropout.Dropout' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) L:\spn\Anaconda3\lib\site-packages\torch\serialization.py:786: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm1d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) Traceback (most recent call last): File "C:\Users\spn\Fake\SimSwap\train.py", line 139, in <module> model.initialize(opt) File "C:\Users\spn\Fake\SimSwap\models\projected_model.py", line 57, in initialize self.netD = ProjectedDiscriminator(diffaug=False, interp224=False, **{}) File "C:\Users\spn\Fake\SimSwap\pg_modules\projected_discriminator.py", line 161, in __init__ self.feature_network = F_RandomProj(**backbone_kwargs) File "C:\Users\spn\Fake\SimSwap\pg_modules\projector.py", line 108, in __init__ self.pretrained, self.scratch = _make_projector(im_res=im_res, cout=self.cout, proj_type=self.proj_type, expand=self.expand) File "C:\Users\spn\Fake\SimSwap\pg_modules\projector.py", line 64, in _make_projector pretrained = _make_efficientnet(model) File "C:\Users\spn\Fake\SimSwap\pg_modules\projector.py", line 35, in _make_efficientnet pretrained.layer0 = nn.Sequential(model.conv_stem, model.bn1, model.act1, *model.blocks[0:2]) File "L:\spn\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1207, in __getattr__ raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'EfficientNet' object has no attribute 'act1'
usmancheema89 commented 2022-07-28 02:17:08 +02:00 (Migrated from github.com)

same issue

same issue
usmancheema89 commented 2022-07-29 02:21:04 +02:00 (Migrated from github.com)

I removed
model.act1
from
pretrained.layer0 = nn.Sequential(model.conv_stem, model.bn1, model.act1, *model.blocks[0:2])

the train starts fine. No idea what impact it would have on the results though. Also this might throw an error if you are trying to load pretrained weights

I removed model.act1 from pretrained.layer0 = nn.Sequential(model.conv_stem, model.bn1, model.act1, *model.blocks[0:2]) the train starts fine. No idea what impact it would have on the results though. Also this might throw an error if you are trying to load pretrained weights
MARCOCHEUNG0124 commented 2022-07-29 04:58:49 +02:00 (Migrated from github.com)

I replaced the model.act1 by nn.SiLU(inplace=False) after checking the meaning of act1. It works fine while training, and the validation result seems to be fine. However, I think I met the problem you mentioned : when I was trying to load my trained 512 simswap to do some infer, I was told that :

Pretrained network G has fewer layers; The following are not initialized: ['down0', 'first_layer', 'last_layer', 'up0']

So now I am trying to infer with the training code provided by @neuralchen

I replaced the `model.act1` by `nn.SiLU(inplace=False)` after checking the meaning of act1. It works fine while training, and the validation result seems to be fine. However, I think I met the problem you mentioned : when I was trying to load my trained 512 simswap to do some infer, I was told that : **Pretrained network G has fewer layers; The following are not initialized: ['down0', 'first_layer', 'last_layer', 'up0']** So now I am trying to infer with the training code provided by @neuralchen
1YasserAmmar1 commented 2022-07-30 07:15:08 +02:00 (Migrated from github.com)

if yo had another problem that tell you
num_samples should be a positive integer value, but got num_samples=0

...................
thin just change the train start code by add the batchsize value --batchSize 4
.............

!python train.py --name simswap224_test --batchSize 4 --gpu_ids 0 --dataset ./content/TrainingData/vggface2_crop_arcfacealign_224 --Gdeep Fals

if yo had another problem that tell you **num_samples should be a positive integer value, but got num_samples=0** ................... **thin just change the train start code by add the batchsize value --batchSize 4** ............. `!python train.py --name simswap224_test --batchSize 4 --gpu_ids 0 --dataset ./content/TrainingData/vggface2_crop_arcfacealign_224 --Gdeep Fals`
zwang970201 commented 2022-08-04 03:05:58 +02:00 (Migrated from github.com)

Is it possible to solve this problem without modifying the training script?

Is it possible to solve this problem without modifying the training script?
1YasserAmmar1 commented 2022-08-04 04:01:01 +02:00 (Migrated from github.com)

@zwang970201
You can't :(
I search for this problem for 1 week and this was the best Solution

@zwang970201 You can't :( I search for this problem for 1 week and this was the best Solution
usmancheema89 commented 2022-08-08 03:08:01 +02:00 (Migrated from github.com)

if yo had another problem that tell you num_samples should be a positive integer value, but got num_samples=0

................... thin just change the train start code by add the batchsize value --batchSize 4 .............

!python train.py --name simswap224_test --batchSize 4 --gpu_ids 0 --dataset ./content/TrainingData/vggface2_crop_arcfacealign_224 --Gdeep Fals

I observed that error with two few classes, that is the number of subjects in training data were too small. I think for each +4 in batch size you need 2 more identities,
batch size 4 = 2 identities
batch size 8 = 4 identities and so on...

> if yo had another problem that tell you **num_samples should be a positive integer value, but got num_samples=0** > > ................... **thin just change the train start code by add the batchsize value --batchSize 4** ............. > > `!python train.py --name simswap224_test --batchSize 4 --gpu_ids 0 --dataset ./content/TrainingData/vggface2_crop_arcfacealign_224 --Gdeep Fals` I observed that error with two few classes, that is the number of subjects in training data were too small. I think for each +4 in batch size you need 2 more identities, batch size 4 = 2 identities batch size 8 = 4 identities and so on...
Deerzh commented 2022-08-15 05:54:37 +02:00 (Migrated from github.com)

I replaced the model.act1 by nn.SiLU(inplace=False) after checking the meaning of act1. It works fine while training, and the validation result seems to be fine. However, I think I met the problem you mentioned : when I was trying to load my trained 512 simswap to do some infer, I was told that :

Pretrained network G has fewer layers; The following are not initialized: ['down0', 'first_layer', 'last_layer', 'up0']

So now I am trying to infer with the training code provided by @neuralchen

Can you tell me the code in which file should be changed?

> I replaced the `model.act1` by `nn.SiLU(inplace=False)` after checking the meaning of act1. It works fine while training, and the validation result seems to be fine. However, I think I met the problem you mentioned : when I was trying to load my trained 512 simswap to do some infer, I was told that : > > **Pretrained network G has fewer layers; The following are not initialized: ['down0', 'first_layer', 'last_layer', 'up0']** > > So now I am trying to infer with the training code provided by @neuralchen Can you tell me the code in which file should be changed?
Sign in to join this conversation.