Rob174 / detection_nappe_hydrocarbures_IMT_cefrem

0 stars 0 forks source link

Create a new hdf5 with augmented patches #28

Closed Rob174 closed 3 years ago

Rob174 commented 3 years ago

Main ideas:

Problems: Currently f4290b7 :

Solution: Put a balanced augmented dataset patches of 1000 px width (square).

Problem: We would like to have rotated source images on which we compute patches. Too much memory required

Solution: Inverse transformation

Rob174 commented 3 years ago

Rotation optimization: inverse transformation

Goal: avoid to load all source image into memory when we only want part of a rotated image

Asset 18@2x
Rob174 commented 3 years ago

More simple solution:

  1. "Make" the rotation transformation (we do not make it but integrate the transformation inside the affine transformation)
  2. center the patch by adding a shift
  3. Use the dsize argument to crop the desired zone

Question: does opencv compute all pixels position ?

Rob174 commented 3 years ago

Test opencv method

We will test if thusing this method speedup the code. For that we will compare two method. We will build an image with a rotated black rectangle of a known shift of (10000,10000) (before a rotation of -45°). We want our algorithm to be able to get only this patch. To achieve that goal we will compare the execution time of two approaches Approach 1:

  1. Construct the original rotation matrix of +45°
  2. Add a shift of (10000,10000) +/- center
  3. Extract with a dsize of 1000,1000

Approach 2:

  1. Rotate the image of 45°
  2. Slice the zone beginning at (10000,10000) with a size of 1000
Rob174 commented 3 years ago

Note: getRotationMatrix2D of opencv2 compose 3 transformation matrices: it translate the center provided to 0,0, rotation and shift the image back

So to create our custom rotation matrix we will add another translation that will put the patch at the upper left corner of the image and we will take on output window of the size of the patch

Note: the destination window is computed taking xwindowsize... pixels and ywindowsize... from the upper left corner of the original full size window

Rob174 commented 3 years ago

Working test in 70236f4

Rob174 commented 3 years ago

Order in which we will compute image transformations: Untitled-2

Rob174 commented 3 years ago

Pb: if we pick a random angle and resize factor how to create coherent patches without duplicates ?

Rob174 commented 3 years ago

Manage augmentation parameters at the dataset level

Idea:

Need to save augmentation to compute for an input image

Rob174 commented 3 years ago

Need to be saved at least at the Augmenter level as multiple classes manage augmentations computation

Rob174 commented 3 years ago

We will include in the new Augmenter1 and RotationResizeMirrors the final resize (to a 256x256 image) and the mirrors: it will allow us to compute a big transformation matrix (that can be used to retrieve original coordinates with the inverse transformation)

Rob174 commented 3 years ago

⚠️ ⚠️ opencv make a transformation matrix inversing traditionnal order: It is done such that to compute the transformation we do transformation_matrix.dot([cols,rows,1])

Rob174 commented 3 years ago

After a profiling we can notice that the read step takes the most time (9938/4 ms = 2484.5 ms ~ 2.5s/call) We cannot avoid that as opencv require a numpy array as input for the transformations

Rob174 commented 3 years ago

Stats: 1 epoch = 49 usable patches = 27min15s -> 33s between 2 usable patches in general 180 patches usable with cache creation script (for one set of augmentations)

Rob174 commented 3 years ago

For further usage, to create the cache use the cache_generation branch

Rob174 commented 3 years ago

Cf #29 for bug informations

Rob174 commented 3 years ago

Done and checked in 3636648