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

Cannot infer the augmentation pipeline phase from the log #440

Open
MarieRoald opened this issue Sep 9, 2024 · 3 comments
Open

Cannot infer the augmentation pipeline phase from the log #440

MarieRoald opened this issue Sep 9, 2024 · 3 comments

Comments

@MarieRoald
Copy link
Contributor

Thank you for creating this useful package! I have a question that I hope you can help me with.

I want to use augraphy in a pipeline for creating synthetic data as part of a research project. However, I need to be able to recreate the exact pipeline that was used on each image after the fact. When reading the documentation I found that I can get the log from the output using pipeline.augment(image)["log"]. However, when looking at the log, I can’t see how I can tell which phase (ink_phase, paper_phase, post_phase or pre_phase) an augmentation belongs to. I also can’t seem to find this in the documentation. So my question is: Is there some way I can find which phase an augmentation should be applied to? If not, what problems might I expect if I input them all in the post_phase?

Example code:

From pprint import pprint
import numpy as np

from augraphy import AugraphyPipeline, augmentations

image = np.random.standard_normal((512, 512))
fold_x = 100
ink_phase = [augmentations.BrightnessTexturize(texturize_range=(0.9, 0.9), deviation=0.1, p=1)]

paper_phase = []

post_phase = [
    augmentations.Folding(
        fold_x=fold_x,
        fold_deviation=(0, 0),
        fold_count=1,
        fold_noise=0,
        fold_angle_range=(0, 0),
        gradient_width=(0.1, 0.1),
        gradient_height=(0.01, 0.01),
        backdrop_color=(0, 0, 0),
        p=1,
    )
]
pipeline = AugraphyPipeline(
    ink_phase=ink_phase,
    paper_phase=paper_phase,
    post_phase=post_phase,
    bounding_boxes=None,
)

pipeline_output = pipeline.augment(image)
pprint(pipeline_output["log"])
{'augmentation_name': ['BrightnessTexturize', 'Folding'],
 'augmentation_parameters': [{'bounding_boxes': [],
                              'deviation': 0.1,
                              'high': 0.9,
                              'keypoints': {},
                              'low': 0.9,
                              'mask': None,
                              'numba_jit': 1,
                              'p': 1,
                              'texturize_range': (0.9, 0.9)},
                             {'backdrop_color': (0, 0, 0),
                              'bounding_boxes': [],
                              'fold_angle_range': (0, 0),
                              'fold_count': 1,
                              'fold_deviation': (0, 0),
                              'fold_noise': 0,
                              'fold_x': 100,
                              'gradient_height': (0.01, 0.01),
                              'gradient_width': (0.1, 0.1),
                              'keypoints': {},
                              'mask': None,
                              'numba_jit': 1,
                              'p': 1}],
 'augmentation_status': [True, True],
 'image_shape': (512, 512),
 'ink_color': -1,
 'paper_color': 255,
 'time': [(BrightnessTexturize(texturize_range=(0.9, 0.9), deviation=0.1, p=1),
           0.040704107999999906),
          (Folding(fold_x=100, fold_deviation=(0, 0), fold_count=1, fold_noise=0, fold_angle_range=(0, 0), gradient_width=(0.1, 0.1), gradient_height=(0.01, 0.01), backdrop_color=(0, 0, 0), p=1),
           0.0025830479999999767)]}

How can I from this log create a pipeline with the two augmentations in the correct phases?

@kwcckw
Copy link
Collaborator

kwcckw commented Sep 10, 2024

Hi, at this moment we can't retrieve phase information from the log, because the augmentation in each phases should be known from the user defined pipeline. You can create a pull request to include this feature too.

It shouldn't causing any further problem if you have all augmentations in the post phase except those augmentations will be overlaid on top of the paper instead of blending with it. To blend it with paper, you need to have them in the ink phase.

@MarieRoald
Copy link
Contributor Author

I see, thank you for the response! I might do a PR on this in the future :)

One more question: Do you have any guidelines or rules of thumb for determining which phase a particular augmentation is the most suitable for?

@kwcckw
Copy link
Collaborator

kwcckw commented Sep 10, 2024

One more question: Do you have any guidelines or rules of thumb for determining which phase a particular augmentation is the most suitable for?

Actually there's no restriction in the augmentations so you can try to have them in different phases and get a different outcomes.

The only augmentation to take note is Rescale where it should be in pre-phase.

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

No branches or pull requests

2 participants