Spaces:
Sleeping
A newer version of the Gradio SDK is available:
5.9.1
Data Transform Migration
Introduction
In MMOCR version 0.x, we implemented a series of Data Transform methods in mmocr/datasets/pipelines/xxx_transforms.py
. However, these modules are scattered all over the place and lack a standardized design. Therefore, we refactored all the data transform modules in MMOCR version 1.x. According to the task type, they are now defined in ocr_transforms.py
, textdet_transforms.py
, and textrecog_transforms.py
, respectively, under mmocr/datasets/transforms
. Specifically, ocr_transforms.py
implements the data augmentation methods for OCR-related tasks in general, while textdet_transforms.py
and textrecog_transforms.py
implement data augmentation transforms related to text detection and text recognition tasks, respectively.
Since some of the modules were renamed, merged or separated during the refactoring process, the new interface and default parameters may be inconsistent with the old version. Therefore, this migration guide will introduce how to configure the new data transforms to achieve the identical behavior as the old version.
Configuration Migration Guide
Data Formatting Related Data Transforms
Collect
+CustomFormatBundle
->PackTextDetInputs
/PackTextRecogInputs
PackxxxInputs
implements both Collect
and CustomFormatBundle
functions, and no longer has key
parameters, the generation of training targets is moved to be done in loss
modules.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
Data Augmentation Related Data Transforms
ResizeOCR
->Resize
,RescaleToHeight
,PadToWidth
The original
ResizeOCR
is now split into three data augmentation modules.When
keep_aspect_ratio=False
, it is equivalent toResize
in version 1.x. Its configuration can be modified as follows.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
When keep_aspect_ratio=True
and max_width=None
. The image will be rescaled to a fixed size alongside the height while keeping the aspect ratio the same as the origin.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
When keep_aspect_ratio=True
and max_width
is a fixed value. The image will be rescaled to a fixed size alongside the height while keeping the aspect ratio the same as the origin. Then, the width will be padded or cropped to max_width
. That is to say, the shape of the output image is always (height, max_width)
.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
RandomRotateTextDet
&RandomRotatePolyInstances
->RandomRotate
We implemented all random rotation-related data augmentation in
RandomRotate
in version 1.x. Its default behavior is identical to theRandomRotateTextDet
in version 0.x.
The default value of "max_angle" might be different from the old version, so the users are suggested to manually set the number.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
For RandomRotatePolyInstances
,it is supposed to set use_canvas=True
。
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
In version 0.x, some data augmentation methods specified execution probability by defining an internal variable "xxx_ratio", such as "rotate_ratio", "crop_ratio", etc. In version 1.x, these parameters have been removed. Now we can use "RandomApply" to wrap different data transforms and specify their execution probabilities.
RandomCropFlip
->TextDetRandomCropFlip
Currently, only the method name has been changed, and other parameters remain the same.
RandomCropPolyInstances
->RandomCrop
In MMOCR version 1.x,
crop_ratio
andinstance_key
are removed. Thegt_polygons
is now used as the target for cropping.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
RandomCropInstances
->TextDetRandomCrop
In MMOCR version 1.x,
crop_ratio
andinstance_key
are removed. Thegt_polygons
is now used as the target for cropping.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
EastRandomCrop
->RandomCrop
+Resize
+mmengine.Pad
EastRandomCrop
was implemented by applying cropping, scaling and padding to the input image. Now, the same effect can be achieved by combining three data transforms.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
RandomScaling
->mmengine.RandomResize
The
RandomScaling
is now replaced withmmengine.RandomResize
.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
By default, the data pipeline will search for the corresponding data transforms from the register of the current *scope*, and if that data transform does not exist, it will continue to search in the upstream library, such as MMCV and MMEngine. For example, the `RandomResize` transform is not implemented in MMOCR, but it can be directly called in the configuration, as the program will automatically search for it from MMCV. In addition, you can also specify *scope* by adding a prefix. For example, `mmengine.RandomResize` will force it to use `RandomResize` implemented in MMEngine, which is useful when a method of the same name exists in both upstream and downstream libraries. It is noteworthy that all of the data transforms implemented in MMCV are registered to MMEngine, that is why we use `mmengine.RandomResize` but not `mmcv.RandomResize`.
SquareResizePad
->Resize
+SourceImagePad
SquareResizePad
implements two branches and uses one of them randomly based on thepad_ratio
. Specifically, one branch first resizes the image and then pads it to a certain size; while the other branch only resizes the image. To enhance the reusability of the different modules, we split this data transform into a combination ofResize
+SourceImagePad
in version 1.x, and control the branches viaRandomChoice
.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
In version 1.x, the random choice wrapper "RandomChoice" replaces "OneOfWrapper", allowing random selection of data transform combinations.
RandomWrapper
->mmengine.RandomApply
In version 1.x, the
RandomWrapper
wrapper has been replaced withRandomApply
in MMEngine, which is used to specify the probability of performing a data transform. And the probabilityp
is now namedprob
.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
OneOfWrapper
->mmengine.RandomChoice
The random choice wrapper is now renamed to
RandomChoice
and is used in exactly the same way as before.ScaleAspectJitter
->ShortScaleAspectJitter
,BoundedScaleAspectJitter
The
ScaleAspectJitter
implemented several different image size jittering strategies, which has now been split into several independent data transforms.When
resize_type='indep_sample_in_range'
, it is equivalent toRandomResize
.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
When resize_type='long_short_bound'
, we implemented BoundedScaleAspectJitter
, which randomly rescales the image so that the long and short sides of the image are around the bound; then jitters the aspect ratio.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|
When resize_type='round_min_img_scale'
, we implemented ShortScaleAspectJitter
, which rescales the image for its shorter side to reach the short_size
and then jitters its aspect ratio, finally rescales the shape guaranteed to be divided by scale_divisor.
MMOCR 0.x Configuration | MMOCR 1.x Configuration |
---|---|
|
|