Skip to content

Adding Differential Binarization model from PaddleOCR to Keras3 #1739

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

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
49f6bb1
Add `DifferentialBinarization` model
gowthamkpr Sep 13, 2024
5b4e011
Added tests for `DifferentialBinarization` losses
gowthamkpr Oct 22, 2024
12ab81c
Moved `DifferentialBinarization` to keras_hub
gowthamkpr Oct 22, 2024
e68512c
Renamed to `differential_binarization.py`
gowthamkpr Oct 22, 2024
0c3235c
Refactorings for `DifferentialBinarization`
gowthamkpr Oct 22, 2024
6797231
More refactorings
gowthamkpr Oct 22, 2024
4845b6a
Fix tests
gowthamkpr Oct 22, 2024
83edf9a
Add preprocessor and image converter
gowthamkpr Oct 29, 2024
f15b7b9
Add presets
gowthamkpr Oct 29, 2024
392dbff
Run formatting script
gowthamkpr Oct 29, 2024
db70eb5
Impl additional tests
gowthamkpr Oct 29, 2024
18fcbfb
Fixed formatting
gowthamkpr Oct 29, 2024
898235d
Removed copyright statements
gowthamkpr Oct 29, 2024
eaec868
Fix tests, run `api_gen.sh`
gowthamkpr Oct 29, 2024
21b6312
Merge branch 'master' into diffbin
gowthamkpr Oct 29, 2024
9fb6e65
Addressed comments
gowthamkpr Nov 11, 2024
83b66ed
Merge with local branch
gowthamkpr Nov 11, 2024
e4a334d
Fixed torch and jax tests
gowthamkpr Nov 13, 2024
49d6f6d
Improved code readability
gowthamkpr Nov 14, 2024
d96b899
Improved/added docstrings
gowthamkpr Nov 22, 2024
2f27981
Added `ImageTextDetector` task
gowthamkpr Nov 25, 2024
66afeb9
Run `api_gen.sh`
gowthamkpr Nov 25, 2024
1d91e76
Fix tensor/array usage
gowthamkpr Dec 17, 2024
e999ad9
Sync with master (new linter)
gowthamkpr Dec 17, 2024
3fd3b6f
Shorten docstring
gowthamkpr Dec 17, 2024
af934f5
Renamed to DiffBin
gowthamkpr Dec 18, 2024
c111bd1
Fixed docstring
gowthamkpr Jan 22, 2025
738786c
Rename `DiffBinOCR` -> `DiffBinImageTextDetector`
gowthamkpr Jan 22, 2025
c06d6cb
Merge branch 'keras-hub' into diffbin3
gowthamkpr Jan 27, 2025
f047012
`diffbin_ocr_test.py` -> `diffbin_textdetector_test.py`
gowthamkpr Jan 27, 2025
26c16e4
Added weight conversion script
gowthamkpr Jan 27, 2025
464482c
Fixed formatting
gowthamkpr Jan 27, 2025
ca83afe
Corrected a few comments
gowthamkpr Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
gowthamkpr committed Oct 22, 2024
commit 4845b6a754b49cd54a3c8fc4bf4c373422359cf3
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import keras
from keras import layers

from keras_hub.src.api_export import keras_hub_export
Expand Down Expand Up @@ -53,9 +54,16 @@ def __init__(
def get_config(self):
config = super().get_config()
config["fpn_channels"] = self.fpn_channels
config["image_encoder"] = self.image_encoder
config["image_encoder"] = keras.layers.serialize(self.image_encoder)
return config

@classmethod
def from_config(cls, config):
config["image_encoder"] = keras.layers.deserialize(
config["image_encoder"]
)
return cls(**config)


def diffbin_fpn_model(inputs, out_channels):
in2 = layers.Conv2D(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,40 @@
from keras_hub.src.models.differential_binarization.differential_binarization import (
DifferentialBinarization,
)
from keras_hub.src.models.differential_binarization.differential_binarization_backbone import (
DifferentialBinarizationBackbone,
)
from keras_hub.src.models.resnet.resnet_backbone import ResNetBackbone
from keras_hub.src.models.resnet.resnet_image_classifier_preprocessor import (
ResNetImageClassifierPreprocessor,
)
from keras_hub.src.tests.test_case import TestCase


class DifferentialBinarizationTest(TestCase):
def setUp(self):
self.images = ops.ones((2, 224, 224, 3))
self.labels = ops.zeros((2, 224, 224, 4))
self.backbone = ResNetBackbone(
image_encoder = ResNetBackbone(
input_conv_filters=[64],
input_conv_kernel_sizes=[7],
stackwise_num_filters=[64, 128, 256, 512],
stackwise_num_blocks=[3, 4, 6, 3],
stackwise_num_strides=[1, 2, 2, 2],
block_type="bottleneck_block",
image_shape=(224, 224, 3),
include_rescaling=False,
)
self.backbone = DifferentialBinarizationBackbone(
image_encoder=image_encoder
)
self.preprocessor = ResNetImageClassifierPreprocessor()
self.init_kwargs = {
"backbone": self.backbone,
"preprocessor": self.preprocessor,
}
self.train_data = (self.images, self.labels)

def test_basics(self):
pytest.skip(
reason="TODO: enable after preprocessor flow is figured out"
)
self.run_task_test(
cls=DifferentialBinarization,
init_kwargs=self.init_kwargs,
Expand Down