-
Notifications
You must be signed in to change notification settings - Fork 7
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
alobugdays/241-aten-w-mergeable-properties #244
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thibo73800 I gave more explanations & a minimal example in issue #241 |
The following work because there is indeed no conflicts between the properties f1 = aloscene.Frame(np.zeros((3, 200, 300)))
f2 = aloscene.Frame(np.zeros((3, 200, 300)))
f1.baseline = 0.5
f2.baseline = 0.5
c = torch.cat([f1.batch(), f2.batch()], dim=0) The following will not work. But this is an expected behavior. Otherwise we could insert hidden issue in the pipeline. f1.baseline = 0.5
f2.baseline = 0.6
c = torch.cat([f1.batch(), f2.batch()], dim=0) An alternative way to do could be to create a new augmented tensor (Not a default child but a one that could be create into a specific datapipeline) baselines_1 = aloscene.tensors.AugmentedTensor(torch.as_tensor([0.5]), names=("N",))
baselines_2 = aloscene.tensors.AugmentedTensor(torch.as_tensor([0.6]), names=("N",))
f1.add_child("baselines", baselines_1, align_dim=["B","T"], mergeable=True)
f2.add_child("baselines", baselines_2, align_dim=["B","T"], mergeable=True)
c = torch.cat([f1.batch(), f2.batch()], dim=0) I'm don't like the ideas of simply doing a concat on the properties if they're different since it could break some other mechanism related to child and augmented tensors (slice for example will not work for properties). An alternative could be to automatically create a new child as above when trying to merge tensors with different properties. But I don't think it must be the default behavior. By the way: a1d27cdc1628557c44bb28f031bcd11e73df896f |
I agree. I specifically don't like the idea of silently merging a property that should not be merged. |
Can the projection and distortion properties of atens already be expressed as childs ? @jsalotti @thibo73800 |
Distortion should be OK, because it is numerical. Projection is more complicated because they are string.
setting to tensor :
Note : this implies to break retro-compatibility with code already using the projection property. But this could be a good practice to not use string properties anymore, because they are not easily represented into tensor. @thibo73800 what do you think ? |
@jsalotti Agree, also if one want to link the text with the child we have the |
I still think that it is a dangerous idea to merge with different values for the same property. For example with projection, the function But maybe in some cases it still is absolutely necessary to merge such tensor, even if it break some other behavior ? @tflahaul could you cite one scenario where it is the case ? |
@jsalotti In our case we want to train a model on data with different projections & distortion coefficients. Therefore we need to create batches of tensors using these different properties. Since we only want to train the model, functions like For example, instead of doing this in if projection == "kumler_bauer": # or Projection.KUMLER_BAUER
...
elif projection == "equidistant":
... we could wrap it in a more general " def project(merged_aten):
projmap = {
"kumler_bauer": project_kumler_bauer,
"equidistant" : project_equidistant,
"pinhole" : project_pinhole,
}
if isinstance(merged_aten.projection, str): # no merge happened
projmap[projection](merged_aten, merged_aten.distortion)
elif isinstance(merged_aten.projection, list):
for index, projection in enumerate(frame.projection):
projmap[projection](frame[index], frame.distortion[index]) (just a workaround thought, this needs more discussion) |
@tflahaul the idea behind your code sample seems good, but I think we will encounter some problems. These problems are caused by the difference between Properties lack some interesting features that children have : a child is an Some example following the idea of your code sample : f1 = Frame(torch.ones((1,3,10,10)), names=("T","C","H", "W"))
f2 = f1.clone()
f1.projection = "pinhole"
f2.projection = "kumler_bauer"
f = torch.cat([f1,f2], axis=0) # concat along temporal axis
f = f.batch() # add batch dimension
print(f.projection)
print(f.names) If we follow the idea of creating a list for properties when merging, the output will be: ['pinhole', 'kumler_bauer']
('B', 'T', 'C', 'H', 'W') Then, the projection function would have to guess that the two items of the list correspond to the temporal dimension, which correspond to I think the behavior you want to produce is much closer to what a |
closing since no activity since November |
Merge augmented tensors properties into lists instead of throwing assertion errors.
Fix issue #241
_merge_tensor
's behavior is unchanged when the properties are the same.Example when using
torch.cat((a, b, c), dim=0)
with a, b, c being tensors with DIFFERENT projection propertiesBefore:
After:
Example when using
torch.cat((a, b, c), dim=0)
with a, b, c being tensors with SAME projection propertiesBefore and after (the behavior is unchanged):
This pull request includes