Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalizing frames with custom mean_std instead of defaulting to resnet #316

Closed
wants to merge 2 commits into from

Conversation

Dee61298
Copy link
Contributor

  • Replaced norm_resnet by norm_meanstd :
    You can now normalize frame with custom mean_std instead of defaulting to resnet.
    Either you pass the mean_std at instanciation or you pass it as a parameter to the norm_meanstd function :
import torch
import aloscene

x=torch.rand(3,600,600)
x=aloscene.Frame(x,mean_std=((0.333,0.333,0.333),(0.333,0.333,0.333)))

x=x.norm_meanstd()
print("normalization de x ",x.normalization)
print("Mean_std de x",x.mean_std)

x=x.norm_meanstd(name="resnet")
print("normalization de x ",x.normalization)
print("Mean_std de x",x.mean_std)

x=x.norm_meanstd(mean_std=((0.440,0.220,0.880),(0.333,0.333,0.333)), name="my_norm")
print("normalization de x ",x.normalization)
print("Mean_std de x",x.mean_std)
  • Output :
normalization de x  None
Mean_std de x ((0.333, 0.333, 0.333), (0.333, 0.333, 0.333))
normalization de x  resnet
Mean_std de x ((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
normalization de x  my_norm
Mean_std de x ((0.44, 0.22, 0.88), (0.333, 0.333, 0.333))

This pull request includes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

@Dee61298 Dee61298 linked an issue Jan 12, 2023 that may be closed by this pull request
@@ -507,10 +510,27 @@ def mean_std_norm(self, mean, std, name) -> Frame:

return tensor

def norm_meanstd(self, mean_std=None, name=None) -> Frame:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having two methodes with nearly the same name is not a good practice. try to fix mean_std_norm instead

return self.norm_resnet()
elif mean_std is not None and len(mean_std) == 2:
return self.mean_std_norm(mean=mean_std[0], std=mean_std[1], name=name)
elif self.mean_std is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no difference between this condition and the one above.

elif mean_std is not None and len(mean_std) == 2:
return self.mean_std_norm(mean=mean_std[0], std=mean_std[1], name=name)
elif self.mean_std is not None:
return self.mean_std_norm(mean=self.mean_std[0], std=self.mean_std[1], name=name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribute mean_std is used to store the current normalization parameters. You can delete this

@Data-Iab
Copy link
Collaborator

Thing you can add : normlization from minmax -> meanstd

import torch
import aloscene

x = torch.rand(3,10,10)
x = aloscene.Frame(x,mean_std=((0.333,0.333,0.333),(0.333,0.333,0.333)))

x = x.norm_minmax_sym()
x = x.mean_std_norm(mean=(0.333,0.333,0.333), std=(0.333,0.333,0.333), name="custom")  # Exception raised

@Dee61298
Copy link
Contributor Author

Duplicated in #317 with the correct commits. Closing this one.

@Dee61298 Dee61298 closed this Jan 16, 2023
@Dee61298 Dee61298 deleted the 302-rgb-mean-std-normalization-values branch January 16, 2023 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RGB mean & std normalization values
2 participants