keras-hub-nightly 0.15.0.dev20240911134614__py3-none-any.whl → 0.16.0.dev2024092017__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. keras_hub/__init__.py +0 -6
  2. keras_hub/api/__init__.py +1 -0
  3. keras_hub/api/models/__init__.py +22 -17
  4. keras_hub/{src/models/llama3/llama3_preprocessor.py → api/utils/__init__.py} +7 -8
  5. keras_hub/src/api_export.py +15 -9
  6. keras_hub/src/models/albert/albert_text_classifier.py +6 -1
  7. keras_hub/src/models/bert/bert_text_classifier.py +6 -1
  8. keras_hub/src/models/deberta_v3/deberta_v3_text_classifier.py +6 -1
  9. keras_hub/src/models/densenet/densenet_backbone.py +1 -1
  10. keras_hub/src/models/distil_bert/distil_bert_text_classifier.py +6 -1
  11. keras_hub/src/models/f_net/f_net_text_classifier.py +6 -1
  12. keras_hub/src/models/gemma/gemma_decoder_block.py +1 -1
  13. keras_hub/src/models/gpt2/gpt2_preprocessor.py +7 -78
  14. keras_hub/src/models/pali_gemma/pali_gemma_tokenizer.py +1 -1
  15. keras_hub/src/models/preprocessor.py +1 -5
  16. keras_hub/src/models/resnet/resnet_backbone.py +3 -16
  17. keras_hub/src/models/resnet/resnet_image_classifier.py +26 -3
  18. keras_hub/src/models/resnet/resnet_presets.py +12 -12
  19. keras_hub/src/models/retinanet/__init__.py +13 -0
  20. keras_hub/src/models/retinanet/anchor_generator.py +175 -0
  21. keras_hub/src/models/retinanet/box_matcher.py +259 -0
  22. keras_hub/src/models/retinanet/non_max_supression.py +578 -0
  23. keras_hub/src/models/roberta/roberta_text_classifier.py +6 -1
  24. keras_hub/src/models/task.py +6 -6
  25. keras_hub/src/models/text_classifier.py +12 -1
  26. keras_hub/src/models/xlm_roberta/xlm_roberta_text_classifier.py +6 -1
  27. keras_hub/src/tests/test_case.py +21 -0
  28. keras_hub/src/tokenizers/byte_pair_tokenizer.py +1 -0
  29. keras_hub/src/tokenizers/sentence_piece_tokenizer.py +1 -0
  30. keras_hub/src/tokenizers/word_piece_tokenizer.py +1 -0
  31. keras_hub/src/utils/imagenet/__init__.py +13 -0
  32. keras_hub/src/utils/imagenet/imagenet_utils.py +1067 -0
  33. keras_hub/src/utils/preset_utils.py +24 -33
  34. keras_hub/src/utils/tensor_utils.py +14 -14
  35. keras_hub/src/utils/timm/convert_resnet.py +0 -1
  36. keras_hub/src/utils/timm/preset_loader.py +6 -7
  37. keras_hub/src/version_utils.py +1 -1
  38. keras_hub_nightly-0.16.0.dev2024092017.dist-info/METADATA +202 -0
  39. {keras_hub_nightly-0.15.0.dev20240911134614.dist-info → keras_hub_nightly-0.16.0.dev2024092017.dist-info}/RECORD +41 -45
  40. {keras_hub_nightly-0.15.0.dev20240911134614.dist-info → keras_hub_nightly-0.16.0.dev2024092017.dist-info}/WHEEL +1 -1
  41. keras_hub/src/models/bart/bart_preprocessor.py +0 -264
  42. keras_hub/src/models/bloom/bloom_preprocessor.py +0 -178
  43. keras_hub/src/models/electra/electra_preprocessor.py +0 -155
  44. keras_hub/src/models/falcon/falcon_preprocessor.py +0 -180
  45. keras_hub/src/models/gemma/gemma_preprocessor.py +0 -184
  46. keras_hub/src/models/gpt_neo_x/gpt_neo_x_preprocessor.py +0 -138
  47. keras_hub/src/models/llama/llama_preprocessor.py +0 -182
  48. keras_hub/src/models/mistral/mistral_preprocessor.py +0 -183
  49. keras_hub/src/models/opt/opt_preprocessor.py +0 -181
  50. keras_hub/src/models/phi3/phi3_preprocessor.py +0 -183
  51. keras_hub_nightly-0.15.0.dev20240911134614.dist-info/METADATA +0 -33
  52. {keras_hub_nightly-0.15.0.dev20240911134614.dist-info → keras_hub_nightly-0.16.0.dev2024092017.dist-info}/top_level.txt +0 -0
@@ -18,6 +18,7 @@ import pathlib
18
18
  import re
19
19
 
20
20
  import keras
21
+ import numpy as np
21
22
  import tensorflow as tf
22
23
  from absl.testing import parameterized
23
24
  from keras import ops
@@ -493,6 +494,7 @@ class TestCase(tf.test.TestCase, parameterized.TestCase):
493
494
  run_mixed_precision_check=run_mixed_precision_check,
494
495
  run_quantization_check=run_quantization_check,
495
496
  )
497
+
496
498
  if expected_pyramid_output_keys:
497
499
  backbone = cls(**init_kwargs)
498
500
  model = keras.models.Model(
@@ -522,6 +524,12 @@ class TestCase(tf.test.TestCase, parameterized.TestCase):
522
524
  input_data = ops.transpose(input_data, axes=(2, 0, 1))
523
525
  elif len(input_data_shape) == 4:
524
526
  input_data = ops.transpose(input_data, axes=(0, 3, 1, 2))
527
+ if len(expected_output_shape) == 3:
528
+ x = expected_output_shape
529
+ expected_output_shape = (x[0], x[2], x[1])
530
+ elif len(expected_output_shape) == 4:
531
+ x = expected_output_shape
532
+ expected_output_shape = (x[0], x[3], x[1], x[2])
525
533
  if "image_shape" in init_kwargs:
526
534
  init_kwargs = init_kwargs.copy()
527
535
  init_kwargs["image_shape"] = tuple(
@@ -592,6 +600,7 @@ class TestCase(tf.test.TestCase, parameterized.TestCase):
592
600
  expected_output=None,
593
601
  expected_output_shape=None,
594
602
  expected_partial_output=None,
603
+ expected_labels=None,
595
604
  ):
596
605
  """Run instantiation and a forward pass for a preset."""
597
606
  with self.assertRaises(Exception):
@@ -629,5 +638,17 @@ class TestCase(tf.test.TestCase, parameterized.TestCase):
629
638
 
630
639
  tree.map_structure(compare, output, expected_partial_output)
631
640
 
641
+ if expected_labels is not None:
642
+ output = ops.argmax(output, axis=-1)
643
+ self.assertAllEqual(output, expected_labels)
644
+
632
645
  def get_test_data_dir(self):
633
646
  return str(pathlib.Path(__file__).parent / "test_data")
647
+
648
+ def load_test_image(self, target_size=None):
649
+ # From https://commons.wikimedia.org/wiki/File:California_quail.jpg
650
+ path = os.path.join(self.get_test_data_dir(), "test_image.jpg")
651
+ img = keras.utils.load_img(
652
+ path, target_size=target_size, keep_aspect_ratio=True
653
+ )
654
+ return np.array(img)
@@ -540,6 +540,7 @@ class BytePairTokenizer(tokenizer.Tokenizer):
540
540
  if self.add_prefix_space:
541
541
  inputs = tf.strings.join([" ", inputs])
542
542
 
543
+ inputs = tf.convert_to_tensor(inputs)
543
544
  unbatched = inputs.shape.rank == 0
544
545
  if unbatched:
545
546
  inputs = tf.expand_dims(inputs, 0)
@@ -238,6 +238,7 @@ class SentencePieceTokenizer(tokenizer.Tokenizer):
238
238
  @preprocessing_function
239
239
  def tokenize(self, inputs):
240
240
  self._check_vocabulary()
241
+ inputs = tf.convert_to_tensor(inputs)
241
242
  unbatched = inputs.shape.rank == 0
242
243
  if unbatched:
243
244
  inputs = tf.expand_dims(inputs, 0)
@@ -473,6 +473,7 @@ class WordPieceTokenizer(tokenizer.Tokenizer):
473
473
  @preprocessing_function
474
474
  def tokenize(self, inputs):
475
475
  self._check_vocabulary()
476
+ inputs = tf.convert_to_tensor(inputs)
476
477
  unbatched = inputs.shape.rank == 0
477
478
  pattern = None
478
479
  if self.split and self.special_tokens_in_strings:
@@ -0,0 +1,13 @@
1
+ # Copyright 2024 The KerasNLP Authors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.