keras-hub-nightly 0.16.1.dev202409250340__py3-none-any.whl → 0.16.1.dev202409270338__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.
- keras_hub/__init__.py +0 -13
- keras_hub/api/__init__.py +0 -13
- keras_hub/api/bounding_box/__init__.py +0 -13
- keras_hub/api/layers/__init__.py +3 -13
- keras_hub/api/metrics/__init__.py +0 -13
- keras_hub/api/models/__init__.py +16 -13
- keras_hub/api/samplers/__init__.py +0 -13
- keras_hub/api/tokenizers/__init__.py +1 -13
- keras_hub/api/utils/__init__.py +0 -13
- keras_hub/src/__init__.py +0 -13
- keras_hub/src/api_export.py +0 -14
- keras_hub/src/bounding_box/__init__.py +0 -13
- keras_hub/src/bounding_box/converters.py +0 -13
- keras_hub/src/bounding_box/formats.py +0 -13
- keras_hub/src/bounding_box/iou.py +1 -13
- keras_hub/src/bounding_box/to_dense.py +0 -14
- keras_hub/src/bounding_box/to_ragged.py +0 -13
- keras_hub/src/bounding_box/utils.py +0 -13
- keras_hub/src/bounding_box/validate_format.py +0 -14
- keras_hub/src/layers/__init__.py +0 -13
- keras_hub/src/layers/modeling/__init__.py +0 -13
- keras_hub/src/layers/modeling/alibi_bias.py +0 -13
- keras_hub/src/layers/modeling/cached_multi_head_attention.py +0 -14
- keras_hub/src/layers/modeling/f_net_encoder.py +0 -14
- keras_hub/src/layers/modeling/masked_lm_head.py +0 -14
- keras_hub/src/layers/modeling/position_embedding.py +0 -14
- keras_hub/src/layers/modeling/reversible_embedding.py +0 -14
- keras_hub/src/layers/modeling/rotary_embedding.py +0 -14
- keras_hub/src/layers/modeling/sine_position_encoding.py +0 -14
- keras_hub/src/layers/modeling/token_and_position_embedding.py +0 -14
- keras_hub/src/layers/modeling/transformer_decoder.py +0 -14
- keras_hub/src/layers/modeling/transformer_encoder.py +0 -14
- keras_hub/src/layers/modeling/transformer_layer_utils.py +0 -14
- keras_hub/src/layers/preprocessing/__init__.py +0 -13
- keras_hub/src/layers/preprocessing/audio_converter.py +0 -13
- keras_hub/src/layers/preprocessing/image_converter.py +0 -13
- keras_hub/src/layers/preprocessing/masked_lm_mask_generator.py +0 -15
- keras_hub/src/layers/preprocessing/multi_segment_packer.py +0 -14
- keras_hub/src/layers/preprocessing/preprocessing_layer.py +0 -14
- keras_hub/src/layers/preprocessing/random_deletion.py +0 -14
- keras_hub/src/layers/preprocessing/random_swap.py +0 -14
- keras_hub/src/layers/preprocessing/resizing_image_converter.py +0 -13
- keras_hub/src/layers/preprocessing/start_end_packer.py +0 -15
- keras_hub/src/metrics/__init__.py +0 -13
- keras_hub/src/metrics/bleu.py +0 -14
- keras_hub/src/metrics/edit_distance.py +0 -14
- keras_hub/src/metrics/perplexity.py +0 -14
- keras_hub/src/metrics/rouge_base.py +0 -14
- keras_hub/src/metrics/rouge_l.py +0 -14
- keras_hub/src/metrics/rouge_n.py +0 -14
- keras_hub/src/models/__init__.py +0 -13
- keras_hub/src/models/albert/__init__.py +0 -14
- keras_hub/src/models/albert/albert_backbone.py +0 -14
- keras_hub/src/models/albert/albert_masked_lm.py +0 -14
- keras_hub/src/models/albert/albert_masked_lm_preprocessor.py +0 -14
- keras_hub/src/models/albert/albert_presets.py +0 -14
- keras_hub/src/models/albert/albert_text_classifier.py +0 -14
- keras_hub/src/models/albert/albert_text_classifier_preprocessor.py +0 -14
- keras_hub/src/models/albert/albert_tokenizer.py +0 -14
- keras_hub/src/models/backbone.py +0 -14
- keras_hub/src/models/bart/__init__.py +0 -14
- keras_hub/src/models/bart/bart_backbone.py +0 -14
- keras_hub/src/models/bart/bart_presets.py +0 -13
- keras_hub/src/models/bart/bart_seq_2_seq_lm.py +0 -15
- keras_hub/src/models/bart/bart_seq_2_seq_lm_preprocessor.py +0 -15
- keras_hub/src/models/bart/bart_tokenizer.py +0 -15
- keras_hub/src/models/bert/__init__.py +0 -14
- keras_hub/src/models/bert/bert_backbone.py +0 -14
- keras_hub/src/models/bert/bert_masked_lm.py +0 -14
- keras_hub/src/models/bert/bert_masked_lm_preprocessor.py +0 -14
- keras_hub/src/models/bert/bert_presets.py +0 -13
- keras_hub/src/models/bert/bert_text_classifier.py +0 -14
- keras_hub/src/models/bert/bert_text_classifier_preprocessor.py +0 -14
- keras_hub/src/models/bert/bert_tokenizer.py +0 -14
- keras_hub/src/models/bloom/__init__.py +0 -14
- keras_hub/src/models/bloom/bloom_attention.py +0 -13
- keras_hub/src/models/bloom/bloom_backbone.py +0 -14
- keras_hub/src/models/bloom/bloom_causal_lm.py +0 -15
- keras_hub/src/models/bloom/bloom_causal_lm_preprocessor.py +0 -15
- keras_hub/src/models/bloom/bloom_decoder.py +0 -13
- keras_hub/src/models/bloom/bloom_presets.py +0 -13
- keras_hub/src/models/bloom/bloom_tokenizer.py +0 -15
- keras_hub/src/models/causal_lm.py +0 -14
- keras_hub/src/models/causal_lm_preprocessor.py +0 -13
- keras_hub/src/models/clip/__init__.py +0 -0
- keras_hub/src/models/{stable_diffusion_v3 → clip}/clip_encoder_block.py +8 -15
- keras_hub/src/models/clip/clip_preprocessor.py +134 -0
- keras_hub/src/models/clip/clip_text_encoder.py +139 -0
- keras_hub/src/models/{stable_diffusion_v3 → clip}/clip_tokenizer.py +65 -41
- keras_hub/src/models/csp_darknet/__init__.py +0 -13
- keras_hub/src/models/csp_darknet/csp_darknet_backbone.py +0 -13
- keras_hub/src/models/csp_darknet/csp_darknet_image_classifier.py +0 -13
- keras_hub/src/models/deberta_v3/__init__.py +0 -14
- keras_hub/src/models/deberta_v3/deberta_v3_backbone.py +0 -15
- keras_hub/src/models/deberta_v3/deberta_v3_masked_lm.py +0 -15
- keras_hub/src/models/deberta_v3/deberta_v3_masked_lm_preprocessor.py +0 -14
- keras_hub/src/models/deberta_v3/deberta_v3_presets.py +0 -13
- keras_hub/src/models/deberta_v3/deberta_v3_text_classifier.py +0 -15
- keras_hub/src/models/deberta_v3/deberta_v3_text_classifier_preprocessor.py +0 -14
- keras_hub/src/models/deberta_v3/deberta_v3_tokenizer.py +0 -15
- keras_hub/src/models/deberta_v3/disentangled_attention_encoder.py +0 -14
- keras_hub/src/models/deberta_v3/disentangled_self_attention.py +0 -14
- keras_hub/src/models/deberta_v3/relative_embedding.py +0 -14
- keras_hub/src/models/densenet/__init__.py +5 -13
- keras_hub/src/models/densenet/densenet_backbone.py +11 -21
- keras_hub/src/models/densenet/densenet_image_classifier.py +27 -17
- keras_hub/src/models/densenet/densenet_image_classifier_preprocessor.py +27 -0
- keras_hub/src/models/{stable_diffusion_v3/__init__.py → densenet/densenet_image_converter.py} +10 -0
- keras_hub/src/models/densenet/densenet_presets.py +56 -0
- keras_hub/src/models/distil_bert/__init__.py +0 -14
- keras_hub/src/models/distil_bert/distil_bert_backbone.py +0 -15
- keras_hub/src/models/distil_bert/distil_bert_masked_lm.py +0 -15
- keras_hub/src/models/distil_bert/distil_bert_masked_lm_preprocessor.py +0 -14
- keras_hub/src/models/distil_bert/distil_bert_presets.py +0 -13
- keras_hub/src/models/distil_bert/distil_bert_text_classifier.py +0 -15
- keras_hub/src/models/distil_bert/distil_bert_text_classifier_preprocessor.py +0 -15
- keras_hub/src/models/distil_bert/distil_bert_tokenizer.py +0 -15
- keras_hub/src/models/efficientnet/__init__.py +0 -13
- keras_hub/src/models/efficientnet/efficientnet_backbone.py +0 -13
- keras_hub/src/models/efficientnet/fusedmbconv.py +0 -14
- keras_hub/src/models/efficientnet/mbconv.py +0 -14
- keras_hub/src/models/electra/__init__.py +0 -14
- keras_hub/src/models/electra/electra_backbone.py +0 -14
- keras_hub/src/models/electra/electra_presets.py +0 -13
- keras_hub/src/models/electra/electra_tokenizer.py +0 -14
- keras_hub/src/models/f_net/__init__.py +0 -14
- keras_hub/src/models/f_net/f_net_backbone.py +0 -15
- keras_hub/src/models/f_net/f_net_masked_lm.py +0 -15
- keras_hub/src/models/f_net/f_net_masked_lm_preprocessor.py +0 -14
- keras_hub/src/models/f_net/f_net_presets.py +0 -13
- keras_hub/src/models/f_net/f_net_text_classifier.py +0 -15
- keras_hub/src/models/f_net/f_net_text_classifier_preprocessor.py +0 -15
- keras_hub/src/models/f_net/f_net_tokenizer.py +0 -15
- keras_hub/src/models/falcon/__init__.py +0 -14
- keras_hub/src/models/falcon/falcon_attention.py +0 -13
- keras_hub/src/models/falcon/falcon_backbone.py +0 -13
- keras_hub/src/models/falcon/falcon_causal_lm.py +0 -14
- keras_hub/src/models/falcon/falcon_causal_lm_preprocessor.py +0 -14
- keras_hub/src/models/falcon/falcon_presets.py +0 -13
- keras_hub/src/models/falcon/falcon_tokenizer.py +0 -15
- keras_hub/src/models/falcon/falcon_transformer_decoder.py +0 -13
- keras_hub/src/models/feature_pyramid_backbone.py +0 -13
- keras_hub/src/models/gemma/__init__.py +0 -14
- keras_hub/src/models/gemma/gemma_attention.py +0 -13
- keras_hub/src/models/gemma/gemma_backbone.py +0 -15
- keras_hub/src/models/gemma/gemma_causal_lm.py +0 -15
- keras_hub/src/models/gemma/gemma_causal_lm_preprocessor.py +0 -14
- keras_hub/src/models/gemma/gemma_decoder_block.py +0 -13
- keras_hub/src/models/gemma/gemma_presets.py +0 -13
- keras_hub/src/models/gemma/gemma_tokenizer.py +0 -14
- keras_hub/src/models/gemma/rms_normalization.py +0 -14
- keras_hub/src/models/gpt2/__init__.py +0 -14
- keras_hub/src/models/gpt2/gpt2_backbone.py +0 -15
- keras_hub/src/models/gpt2/gpt2_causal_lm.py +0 -15
- keras_hub/src/models/gpt2/gpt2_causal_lm_preprocessor.py +0 -14
- keras_hub/src/models/gpt2/gpt2_preprocessor.py +0 -15
- keras_hub/src/models/gpt2/gpt2_presets.py +0 -13
- keras_hub/src/models/gpt2/gpt2_tokenizer.py +0 -15
- keras_hub/src/models/gpt_neo_x/__init__.py +0 -13
- keras_hub/src/models/gpt_neo_x/gpt_neo_x_attention.py +0 -14
- keras_hub/src/models/gpt_neo_x/gpt_neo_x_backbone.py +0 -14
- keras_hub/src/models/gpt_neo_x/gpt_neo_x_causal_lm.py +0 -14
- keras_hub/src/models/gpt_neo_x/gpt_neo_x_causal_lm_preprocessor.py +0 -14
- keras_hub/src/models/gpt_neo_x/gpt_neo_x_decoder.py +0 -14
- keras_hub/src/models/gpt_neo_x/gpt_neo_x_tokenizer.py +0 -14
- keras_hub/src/models/image_classifier.py +0 -13
- keras_hub/src/models/image_classifier_preprocessor.py +0 -13
- keras_hub/src/models/image_segmenter.py +0 -13
- keras_hub/src/models/llama/__init__.py +0 -14
- keras_hub/src/models/llama/llama_attention.py +0 -13
- keras_hub/src/models/llama/llama_backbone.py +0 -13
- keras_hub/src/models/llama/llama_causal_lm.py +0 -13
- keras_hub/src/models/llama/llama_causal_lm_preprocessor.py +0 -15
- keras_hub/src/models/llama/llama_decoder.py +0 -13
- keras_hub/src/models/llama/llama_layernorm.py +0 -13
- keras_hub/src/models/llama/llama_presets.py +0 -13
- keras_hub/src/models/llama/llama_tokenizer.py +0 -14
- keras_hub/src/models/llama3/__init__.py +0 -14
- keras_hub/src/models/llama3/llama3_backbone.py +0 -14
- keras_hub/src/models/llama3/llama3_causal_lm.py +0 -13
- keras_hub/src/models/llama3/llama3_causal_lm_preprocessor.py +0 -14
- keras_hub/src/models/llama3/llama3_presets.py +0 -13
- keras_hub/src/models/llama3/llama3_tokenizer.py +0 -14
- keras_hub/src/models/masked_lm.py +0 -13
- keras_hub/src/models/masked_lm_preprocessor.py +0 -13
- keras_hub/src/models/mistral/__init__.py +0 -14
- keras_hub/src/models/mistral/mistral_attention.py +0 -13
- keras_hub/src/models/mistral/mistral_backbone.py +0 -14
- keras_hub/src/models/mistral/mistral_causal_lm.py +0 -14
- keras_hub/src/models/mistral/mistral_causal_lm_preprocessor.py +0 -14
- keras_hub/src/models/mistral/mistral_layer_norm.py +0 -13
- keras_hub/src/models/mistral/mistral_presets.py +0 -13
- keras_hub/src/models/mistral/mistral_tokenizer.py +0 -14
- keras_hub/src/models/mistral/mistral_transformer_decoder.py +0 -13
- keras_hub/src/models/mix_transformer/__init__.py +0 -13
- keras_hub/src/models/mix_transformer/mix_transformer_backbone.py +0 -13
- keras_hub/src/models/mix_transformer/mix_transformer_classifier.py +0 -13
- keras_hub/src/models/mix_transformer/mix_transformer_layers.py +0 -13
- keras_hub/src/models/mobilenet/__init__.py +0 -13
- keras_hub/src/models/mobilenet/mobilenet_backbone.py +0 -13
- keras_hub/src/models/mobilenet/mobilenet_image_classifier.py +0 -13
- keras_hub/src/models/opt/__init__.py +0 -14
- keras_hub/src/models/opt/opt_backbone.py +0 -15
- keras_hub/src/models/opt/opt_causal_lm.py +0 -15
- keras_hub/src/models/opt/opt_causal_lm_preprocessor.py +0 -13
- keras_hub/src/models/opt/opt_presets.py +0 -13
- keras_hub/src/models/opt/opt_tokenizer.py +0 -15
- keras_hub/src/models/pali_gemma/__init__.py +0 -13
- keras_hub/src/models/pali_gemma/pali_gemma_backbone.py +0 -13
- keras_hub/src/models/pali_gemma/pali_gemma_causal_lm.py +0 -13
- keras_hub/src/models/pali_gemma/pali_gemma_causal_lm_preprocessor.py +0 -13
- keras_hub/src/models/pali_gemma/pali_gemma_decoder_block.py +0 -14
- keras_hub/src/models/pali_gemma/pali_gemma_image_converter.py +0 -13
- keras_hub/src/models/pali_gemma/pali_gemma_presets.py +0 -13
- keras_hub/src/models/pali_gemma/pali_gemma_tokenizer.py +0 -13
- keras_hub/src/models/pali_gemma/pali_gemma_vit.py +0 -13
- keras_hub/src/models/phi3/__init__.py +0 -14
- keras_hub/src/models/phi3/phi3_attention.py +0 -13
- keras_hub/src/models/phi3/phi3_backbone.py +0 -13
- keras_hub/src/models/phi3/phi3_causal_lm.py +0 -13
- keras_hub/src/models/phi3/phi3_causal_lm_preprocessor.py +0 -14
- keras_hub/src/models/phi3/phi3_decoder.py +0 -13
- keras_hub/src/models/phi3/phi3_layernorm.py +0 -13
- keras_hub/src/models/phi3/phi3_presets.py +0 -13
- keras_hub/src/models/phi3/phi3_rotary_embedding.py +0 -13
- keras_hub/src/models/phi3/phi3_tokenizer.py +0 -13
- keras_hub/src/models/preprocessor.py +51 -32
- keras_hub/src/models/resnet/__init__.py +0 -14
- keras_hub/src/models/resnet/resnet_backbone.py +0 -13
- keras_hub/src/models/resnet/resnet_image_classifier.py +0 -13
- keras_hub/src/models/resnet/resnet_image_classifier_preprocessor.py +0 -14
- keras_hub/src/models/resnet/resnet_image_converter.py +0 -13
- keras_hub/src/models/resnet/resnet_presets.py +0 -13
- keras_hub/src/models/retinanet/__init__.py +0 -13
- keras_hub/src/models/retinanet/anchor_generator.py +0 -14
- keras_hub/src/models/retinanet/box_matcher.py +0 -14
- keras_hub/src/models/retinanet/non_max_supression.py +0 -14
- keras_hub/src/models/roberta/__init__.py +0 -14
- keras_hub/src/models/roberta/roberta_backbone.py +0 -15
- keras_hub/src/models/roberta/roberta_masked_lm.py +0 -15
- keras_hub/src/models/roberta/roberta_masked_lm_preprocessor.py +0 -14
- keras_hub/src/models/roberta/roberta_presets.py +0 -13
- keras_hub/src/models/roberta/roberta_text_classifier.py +0 -15
- keras_hub/src/models/roberta/roberta_text_classifier_preprocessor.py +0 -14
- keras_hub/src/models/roberta/roberta_tokenizer.py +0 -15
- keras_hub/src/models/sam/__init__.py +0 -13
- keras_hub/src/models/sam/sam_backbone.py +0 -14
- keras_hub/src/models/sam/sam_image_segmenter.py +0 -14
- keras_hub/src/models/sam/sam_layers.py +0 -14
- keras_hub/src/models/sam/sam_mask_decoder.py +0 -14
- keras_hub/src/models/sam/sam_prompt_encoder.py +0 -14
- keras_hub/src/models/sam/sam_transformer.py +0 -14
- keras_hub/src/models/seq_2_seq_lm.py +0 -13
- keras_hub/src/models/seq_2_seq_lm_preprocessor.py +0 -13
- keras_hub/src/models/stable_diffusion_3/__init__.py +9 -0
- keras_hub/src/models/stable_diffusion_3/flow_match_euler_discrete_scheduler.py +80 -0
- keras_hub/src/models/{stable_diffusion_v3 → stable_diffusion_3}/mmdit.py +351 -39
- keras_hub/src/models/stable_diffusion_3/stable_diffusion_3_backbone.py +631 -0
- keras_hub/src/models/stable_diffusion_3/stable_diffusion_3_presets.py +31 -0
- keras_hub/src/models/stable_diffusion_3/stable_diffusion_3_text_to_image.py +138 -0
- keras_hub/src/models/stable_diffusion_3/stable_diffusion_3_text_to_image_preprocessor.py +83 -0
- keras_hub/src/models/{stable_diffusion_v3/t5_xxl_text_encoder.py → stable_diffusion_3/t5_encoder.py} +7 -20
- keras_hub/src/models/stable_diffusion_3/vae_image_decoder.py +320 -0
- keras_hub/src/models/t5/__init__.py +0 -14
- keras_hub/src/models/t5/t5_backbone.py +0 -14
- keras_hub/src/models/t5/t5_layer_norm.py +0 -14
- keras_hub/src/models/t5/t5_multi_head_attention.py +0 -14
- keras_hub/src/models/{stable_diffusion_v3/t5_xxl_preprocessor.py → t5/t5_preprocessor.py} +12 -16
- keras_hub/src/models/t5/t5_presets.py +0 -13
- keras_hub/src/models/t5/t5_tokenizer.py +0 -14
- keras_hub/src/models/t5/t5_transformer_layer.py +0 -14
- keras_hub/src/models/task.py +0 -14
- keras_hub/src/models/text_classifier.py +0 -13
- keras_hub/src/models/text_classifier_preprocessor.py +0 -13
- keras_hub/src/models/text_to_image.py +282 -0
- keras_hub/src/models/vgg/__init__.py +0 -13
- keras_hub/src/models/vgg/vgg_backbone.py +0 -13
- keras_hub/src/models/vgg/vgg_image_classifier.py +0 -13
- keras_hub/src/models/vit_det/__init__.py +0 -13
- keras_hub/src/models/vit_det/vit_det_backbone.py +0 -14
- keras_hub/src/models/vit_det/vit_layers.py +0 -15
- keras_hub/src/models/whisper/__init__.py +0 -14
- keras_hub/src/models/whisper/whisper_audio_converter.py +0 -15
- keras_hub/src/models/whisper/whisper_backbone.py +0 -15
- keras_hub/src/models/whisper/whisper_cached_multi_head_attention.py +0 -13
- keras_hub/src/models/whisper/whisper_decoder.py +0 -14
- keras_hub/src/models/whisper/whisper_encoder.py +0 -14
- keras_hub/src/models/whisper/whisper_presets.py +0 -14
- keras_hub/src/models/whisper/whisper_tokenizer.py +0 -14
- keras_hub/src/models/xlm_roberta/__init__.py +0 -14
- keras_hub/src/models/xlm_roberta/xlm_roberta_backbone.py +0 -15
- keras_hub/src/models/xlm_roberta/xlm_roberta_masked_lm.py +0 -15
- keras_hub/src/models/xlm_roberta/xlm_roberta_masked_lm_preprocessor.py +0 -14
- keras_hub/src/models/xlm_roberta/xlm_roberta_presets.py +0 -13
- keras_hub/src/models/xlm_roberta/xlm_roberta_text_classifier.py +0 -15
- keras_hub/src/models/xlm_roberta/xlm_roberta_text_classifier_preprocessor.py +0 -15
- keras_hub/src/models/xlm_roberta/xlm_roberta_tokenizer.py +0 -15
- keras_hub/src/models/xlnet/__init__.py +0 -13
- keras_hub/src/models/xlnet/relative_attention.py +0 -14
- keras_hub/src/models/xlnet/xlnet_backbone.py +0 -14
- keras_hub/src/models/xlnet/xlnet_content_and_query_embedding.py +0 -14
- keras_hub/src/models/xlnet/xlnet_encoder.py +0 -14
- keras_hub/src/samplers/__init__.py +0 -13
- keras_hub/src/samplers/beam_sampler.py +0 -14
- keras_hub/src/samplers/contrastive_sampler.py +0 -14
- keras_hub/src/samplers/greedy_sampler.py +0 -14
- keras_hub/src/samplers/random_sampler.py +0 -14
- keras_hub/src/samplers/sampler.py +0 -14
- keras_hub/src/samplers/serialization.py +0 -14
- keras_hub/src/samplers/top_k_sampler.py +0 -14
- keras_hub/src/samplers/top_p_sampler.py +0 -14
- keras_hub/src/tests/__init__.py +0 -13
- keras_hub/src/tests/test_case.py +0 -14
- keras_hub/src/tokenizers/__init__.py +0 -13
- keras_hub/src/tokenizers/byte_pair_tokenizer.py +0 -14
- keras_hub/src/tokenizers/byte_tokenizer.py +0 -14
- keras_hub/src/tokenizers/sentence_piece_tokenizer.py +0 -14
- keras_hub/src/tokenizers/sentence_piece_tokenizer_trainer.py +0 -14
- keras_hub/src/tokenizers/tokenizer.py +23 -27
- keras_hub/src/tokenizers/unicode_codepoint_tokenizer.py +0 -15
- keras_hub/src/tokenizers/word_piece_tokenizer.py +0 -14
- keras_hub/src/tokenizers/word_piece_tokenizer_trainer.py +0 -15
- keras_hub/src/utils/__init__.py +0 -13
- keras_hub/src/utils/imagenet/__init__.py +0 -13
- keras_hub/src/utils/imagenet/imagenet_utils.py +0 -13
- keras_hub/src/utils/keras_utils.py +0 -14
- keras_hub/src/utils/pipeline_model.py +0 -14
- keras_hub/src/utils/preset_utils.py +32 -76
- keras_hub/src/utils/python_utils.py +0 -13
- keras_hub/src/utils/tensor_utils.py +0 -14
- keras_hub/src/utils/timm/__init__.py +0 -13
- keras_hub/src/utils/timm/convert_densenet.py +107 -0
- keras_hub/src/utils/timm/convert_resnet.py +0 -13
- keras_hub/src/utils/timm/preset_loader.py +3 -13
- keras_hub/src/utils/transformers/__init__.py +0 -13
- keras_hub/src/utils/transformers/convert_albert.py +0 -13
- keras_hub/src/utils/transformers/convert_bart.py +0 -13
- keras_hub/src/utils/transformers/convert_bert.py +0 -13
- keras_hub/src/utils/transformers/convert_distilbert.py +0 -13
- keras_hub/src/utils/transformers/convert_gemma.py +0 -13
- keras_hub/src/utils/transformers/convert_gpt2.py +0 -13
- keras_hub/src/utils/transformers/convert_llama3.py +0 -13
- keras_hub/src/utils/transformers/convert_mistral.py +0 -13
- keras_hub/src/utils/transformers/convert_pali_gemma.py +0 -13
- keras_hub/src/utils/transformers/preset_loader.py +1 -15
- keras_hub/src/utils/transformers/safetensor_utils.py +9 -15
- keras_hub/src/version_utils.py +1 -15
- {keras_hub_nightly-0.16.1.dev202409250340.dist-info → keras_hub_nightly-0.16.1.dev202409270338.dist-info}/METADATA +30 -27
- keras_hub_nightly-0.16.1.dev202409270338.dist-info/RECORD +351 -0
- keras_hub/src/models/stable_diffusion_v3/clip_preprocessor.py +0 -93
- keras_hub/src/models/stable_diffusion_v3/clip_text_encoder.py +0 -149
- keras_hub/src/models/stable_diffusion_v3/mmdit_block.py +0 -317
- keras_hub/src/models/stable_diffusion_v3/vae_attention.py +0 -126
- keras_hub/src/models/stable_diffusion_v3/vae_image_decoder.py +0 -186
- keras_hub_nightly-0.16.1.dev202409250340.dist-info/RECORD +0 -342
- {keras_hub_nightly-0.16.1.dev202409250340.dist-info → keras_hub_nightly-0.16.1.dev202409270338.dist-info}/WHEEL +0 -0
- {keras_hub_nightly-0.16.1.dev202409250340.dist-info → keras_hub_nightly-0.16.1.dev202409270338.dist-info}/top_level.txt +0 -0
@@ -1,19 +1,8 @@
|
|
1
|
-
|
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.
|
1
|
+
from keras_hub.src.api_export import keras_hub_export
|
14
2
|
from keras_hub.src.tokenizers.byte_pair_tokenizer import BytePairTokenizer
|
15
3
|
from keras_hub.src.tokenizers.byte_pair_tokenizer import convert_to_ragged_batch
|
16
4
|
from keras_hub.src.tokenizers.byte_pair_tokenizer import split_strings_for_bpe
|
5
|
+
from keras_hub.src.utils.tensor_utils import preprocessing_function
|
17
6
|
|
18
7
|
try:
|
19
8
|
import tensorflow as tf
|
@@ -21,10 +10,52 @@ except ImportError:
|
|
21
10
|
tf = None
|
22
11
|
|
23
12
|
|
13
|
+
@keras_hub_export(
|
14
|
+
[
|
15
|
+
"keras_hub.tokenizers.CLIPTokenizer",
|
16
|
+
"keras_hub.models.CLIPTokenizer",
|
17
|
+
]
|
18
|
+
)
|
24
19
|
class CLIPTokenizer(BytePairTokenizer):
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
"""A CLIP tokenizer using Byte-Pair Encoding subword segmentation.
|
21
|
+
|
22
|
+
This tokenizer class will tokenize raw strings into integer sequences and
|
23
|
+
is based on `keras_hub.tokenizers.BytePairTokenizer`. Unlike the
|
24
|
+
underlying tokenizer, it will check for all special tokens needed by CLIP
|
25
|
+
models and provides a `from_preset()` method to automatically download
|
26
|
+
a matching vocabulary for a CLIP preset.
|
27
|
+
|
28
|
+
If input is a batch of strings (rank > 0), the layer will output a
|
29
|
+
`tf.RaggedTensor` where the last dimension of the output is ragged.
|
30
|
+
|
31
|
+
If input is a scalar string (rank == 0), the layer will output a dense
|
32
|
+
`tf.Tensor` with static shape `[None]`.
|
33
|
+
|
34
|
+
Args:
|
35
|
+
vocabulary: string or dict, maps token to integer ids. If it is a
|
36
|
+
string, it should be the file path to a json file.
|
37
|
+
merges: string or list, contains the merge rule. If it is a string,
|
38
|
+
it should be the file path to merge rules. The merge rule file
|
39
|
+
should have one merge rule per line. Every merge rule contains
|
40
|
+
merge entities separated by a space.
|
41
|
+
pad_with_end_token: bool. Whether to pad the output with `end_token`.
|
42
|
+
"""
|
43
|
+
|
44
|
+
# TODO: Add example and `backbone_cls` once we have a CLIP model.
|
45
|
+
|
46
|
+
backbone_cls = None
|
47
|
+
|
48
|
+
def __init__(
|
49
|
+
self,
|
50
|
+
vocabulary=None,
|
51
|
+
merges=None,
|
52
|
+
pad_with_end_token=False,
|
53
|
+
**kwargs,
|
54
|
+
):
|
55
|
+
self._add_special_token("<|startoftext|>", "start_token")
|
56
|
+
self._add_special_token("<|endoftext|>", "end_token")
|
57
|
+
self.pad_token_id = 0
|
58
|
+
self.pad_with_end_token = pad_with_end_token
|
28
59
|
|
29
60
|
super().__init__(
|
30
61
|
vocabulary=vocabulary,
|
@@ -35,33 +66,17 @@ class CLIPTokenizer(BytePairTokenizer):
|
|
35
66
|
|
36
67
|
def set_vocabulary_and_merges(self, vocabulary, merges):
|
37
68
|
super().set_vocabulary_and_merges(vocabulary, merges)
|
38
|
-
|
39
|
-
|
40
|
-
# Check for necessary special tokens.
|
41
|
-
if self.end_token not in self.get_vocabulary():
|
42
|
-
raise ValueError(
|
43
|
-
f"Cannot find token `'{self.end_token}'` in the provided "
|
44
|
-
f"`vocabulary`. Please provide `'{self.end_token}'` in "
|
45
|
-
"your `vocabulary` or use a pretrained `vocabulary` name."
|
46
|
-
)
|
47
|
-
|
48
|
-
self.start_token_id = self.token_to_id(self.start_token)
|
49
|
-
self.end_token_id = self.token_to_id(self.end_token)
|
50
|
-
self.pad_token_id = 0
|
51
|
-
else:
|
52
|
-
self.end_token_id = None
|
53
|
-
self.start_token_id = None
|
54
|
-
self.pad_token_id = None
|
69
|
+
if self.pad_with_end_token:
|
70
|
+
self.pad_token_id = self.end_token_id
|
55
71
|
|
56
72
|
def _bpe_merge_and_update_cache(self, tokens):
|
57
73
|
"""Process unseen tokens and add to cache."""
|
58
74
|
words = self._transform_bytes(tokens)
|
59
75
|
|
60
|
-
# In
|
76
|
+
# In CLIP, we need to add `</w>` to the last word.
|
61
77
|
words = tf.strings.reduce_join(words, axis=1, separator=" ")
|
62
78
|
words = tf.strings.join([words, "</w>"])
|
63
79
|
words = tf.strings.split(words, sep=" ")
|
64
|
-
|
65
80
|
tokenized_words = self._bpe_merge(words)
|
66
81
|
|
67
82
|
# For each word, join all its token by a whitespace,
|
@@ -71,17 +86,20 @@ class CLIPTokenizer(BytePairTokenizer):
|
|
71
86
|
)
|
72
87
|
self.cache.insert(tokens, tokenized_words)
|
73
88
|
|
89
|
+
@preprocessing_function
|
74
90
|
def tokenize(self, inputs):
|
75
91
|
self._check_vocabulary()
|
76
|
-
if not isinstance(inputs, (tf.Tensor, tf.RaggedTensor)):
|
77
|
-
inputs = tf.convert_to_tensor(inputs)
|
78
|
-
|
79
92
|
if self.add_prefix_space:
|
80
93
|
inputs = tf.strings.join([" ", inputs])
|
81
94
|
|
82
|
-
|
83
|
-
if
|
95
|
+
unbatched = inputs.shape.rank == 0
|
96
|
+
if unbatched:
|
84
97
|
inputs = tf.expand_dims(inputs, 0)
|
98
|
+
if inputs.shape.rank > 1:
|
99
|
+
raise ValueError(
|
100
|
+
"`tokenize()` inputs should be a string, list of strings, or "
|
101
|
+
f"string tensor with rank < 2. Received: {inputs}"
|
102
|
+
)
|
85
103
|
|
86
104
|
raw_tokens = split_strings_for_bpe(inputs, self.unsplittable_tokens)
|
87
105
|
|
@@ -131,12 +149,13 @@ class CLIPTokenizer(BytePairTokenizer):
|
|
131
149
|
tokens = tokens.to_tensor(shape=output_shape)
|
132
150
|
|
133
151
|
# Convert to a dense output if input in scalar
|
134
|
-
if
|
152
|
+
if unbatched:
|
135
153
|
tokens = tf.squeeze(tokens, 0)
|
136
154
|
tf.ensure_shape(tokens, shape=[self.sequence_length])
|
137
155
|
|
138
156
|
return tokens
|
139
157
|
|
158
|
+
@preprocessing_function
|
140
159
|
def detokenize(self, inputs):
|
141
160
|
self._check_vocabulary()
|
142
161
|
inputs, unbatched, _ = convert_to_ragged_batch(inputs)
|
@@ -160,6 +179,11 @@ class CLIPTokenizer(BytePairTokenizer):
|
|
160
179
|
|
161
180
|
def get_config(self):
|
162
181
|
config = super().get_config()
|
182
|
+
config.update(
|
183
|
+
{
|
184
|
+
"pad_with_end_token": self.pad_with_end_token,
|
185
|
+
}
|
186
|
+
)
|
163
187
|
# In the constructor, we pass the list of special tokens to the
|
164
188
|
# `unsplittable_tokens` arg of the superclass' constructor. Hence, we
|
165
189
|
# delete it from the config here.
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
@@ -1,16 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
1
|
import keras
|
15
2
|
from keras import layers
|
16
3
|
|
@@ -1,16 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
1
|
import keras
|
15
2
|
|
16
3
|
from keras_hub.src.api_export import keras_hub_export
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
1
|
from keras_hub.src.models.deberta_v3.deberta_v3_backbone import (
|
16
2
|
DebertaV3Backbone,
|
17
3
|
)
|
@@ -1,18 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
|
-
|
16
1
|
import keras
|
17
2
|
|
18
3
|
from keras_hub.src.api_export import keras_hub_export
|
@@ -1,18 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
|
-
|
16
1
|
import keras
|
17
2
|
|
18
3
|
from keras_hub.src.api_export import keras_hub_export
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
1
|
import keras
|
16
2
|
|
17
3
|
from keras_hub.src.api_export import keras_hub_export
|
@@ -1,16 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
1
|
"""DeBERTa model preset configurations."""
|
15
2
|
|
16
3
|
backbone_presets = {
|
@@ -1,18 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
|
-
|
16
1
|
import keras
|
17
2
|
|
18
3
|
from keras_hub.src.api_export import keras_hub_export
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
1
|
import keras
|
16
2
|
|
17
3
|
from keras_hub.src.api_export import keras_hub_export
|
@@ -1,18 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
|
-
|
16
1
|
from keras_hub.src.api_export import keras_hub_export
|
17
2
|
from keras_hub.src.models.deberta_v3.deberta_v3_backbone import (
|
18
3
|
DebertaV3Backbone,
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
1
|
import keras
|
16
2
|
|
17
3
|
from keras_hub.src.models.deberta_v3.disentangled_self_attention import (
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
1
|
import math
|
16
2
|
|
17
3
|
import keras
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
|
-
|
15
1
|
import keras
|
16
2
|
from keras import ops
|
17
3
|
|
@@ -1,13 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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.
|
1
|
+
from keras_hub.src.models.densenet.densenet_backbone import DenseNetBackbone
|
2
|
+
from keras_hub.src.models.densenet.densenet_presets import backbone_presets
|
3
|
+
from keras_hub.src.utils.preset_utils import register_presets
|
4
|
+
|
5
|
+
register_presets(backbone_presets, DenseNetBackbone)
|
@@ -1,16 +1,3 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
1
|
import keras
|
15
2
|
|
16
3
|
from keras_hub.src.api_export import keras_hub_export
|
@@ -92,11 +79,14 @@ class DenseNetBackbone(FeaturePyramidBackbone):
|
|
92
79
|
channel_axis,
|
93
80
|
stackwise_num_repeats[stack_index],
|
94
81
|
growth_rate,
|
95
|
-
name=f"
|
82
|
+
name=f"stack{stack_index+1}",
|
96
83
|
)
|
97
84
|
pyramid_outputs[f"P{index}"] = x
|
98
85
|
x = apply_transition_block(
|
99
|
-
x,
|
86
|
+
x,
|
87
|
+
channel_axis,
|
88
|
+
compression_ratio,
|
89
|
+
name=f"transition{stack_index+1}",
|
100
90
|
)
|
101
91
|
|
102
92
|
x = apply_dense_block(
|
@@ -104,7 +94,7 @@ class DenseNetBackbone(FeaturePyramidBackbone):
|
|
104
94
|
channel_axis,
|
105
95
|
stackwise_num_repeats[-1],
|
106
96
|
growth_rate,
|
107
|
-
name=f"
|
97
|
+
name=f"stack{len(stackwise_num_repeats)}",
|
108
98
|
)
|
109
99
|
pyramid_outputs[f"P{len(stackwise_num_repeats) + 1}"] = x
|
110
100
|
x = keras.layers.BatchNormalization(
|
@@ -148,7 +138,7 @@ def apply_dense_block(x, channel_axis, num_repeats, growth_rate, name=None):
|
|
148
138
|
|
149
139
|
for i in range(num_repeats):
|
150
140
|
x = apply_conv_block(
|
151
|
-
x, channel_axis, growth_rate, name=f"{name}
|
141
|
+
x, channel_axis, growth_rate, name=f"{name}_block{i+1}"
|
152
142
|
)
|
153
143
|
return x
|
154
144
|
|
@@ -196,9 +186,9 @@ def apply_conv_block(x, channel_axis, growth_rate, name=None):
|
|
196
186
|
|
197
187
|
shortcut = x
|
198
188
|
x = keras.layers.BatchNormalization(
|
199
|
-
axis=channel_axis, epsilon=BN_EPSILON, name=f"{name}
|
189
|
+
axis=channel_axis, epsilon=BN_EPSILON, name=f"{name}_1_bn"
|
200
190
|
)(x)
|
201
|
-
x = keras.layers.Activation("relu", name=f"{name}
|
191
|
+
x = keras.layers.Activation("relu", name=f"{name}_1_relu")(x)
|
202
192
|
x = keras.layers.Conv2D(
|
203
193
|
4 * growth_rate,
|
204
194
|
1,
|
@@ -207,9 +197,9 @@ def apply_conv_block(x, channel_axis, growth_rate, name=None):
|
|
207
197
|
name=f"{name}_1_conv",
|
208
198
|
)(x)
|
209
199
|
x = keras.layers.BatchNormalization(
|
210
|
-
axis=channel_axis, epsilon=BN_EPSILON, name=f"{name}
|
200
|
+
axis=channel_axis, epsilon=BN_EPSILON, name=f"{name}_2_bn"
|
211
201
|
)(x)
|
212
|
-
x = keras.layers.Activation("relu", name=f"{name}
|
202
|
+
x = keras.layers.Activation("relu", name=f"{name}_2_relu")(x)
|
213
203
|
x = keras.layers.Conv2D(
|
214
204
|
growth_rate,
|
215
205
|
3,
|
@@ -1,20 +1,10 @@
|
|
1
|
-
# Copyright 2024 The KerasHub 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.
|
14
1
|
import keras
|
15
2
|
|
16
3
|
from keras_hub.src.api_export import keras_hub_export
|
17
4
|
from keras_hub.src.models.densenet.densenet_backbone import DenseNetBackbone
|
5
|
+
from keras_hub.src.models.densenet.densenet_image_classifier_preprocessor import (
|
6
|
+
DenseNetImageClassifierPreprocessor,
|
7
|
+
)
|
18
8
|
from keras_hub.src.models.image_classifier import ImageClassifier
|
19
9
|
|
20
10
|
|
@@ -32,7 +22,13 @@ class DenseNetImageClassifier(ImageClassifier):
|
|
32
22
|
num_classes: int. The number of classes to predict.
|
33
23
|
activation: `None`, str or callable. The activation function to use on
|
34
24
|
the `Dense` layer. Set `activation=None` to return the output
|
35
|
-
logits. Defaults to `
|
25
|
+
logits. Defaults to `None`.
|
26
|
+
pooling: A pooling layer to use before the final classification layer,
|
27
|
+
must be one of "avg" or "max". Use "avg" for
|
28
|
+
`GlobalAveragePooling2D` and "max" for "GlobalMaxPooling2D.
|
29
|
+
preprocessor: A `keras_hub.models.DenseNetImageClassifierPreprocessor`
|
30
|
+
or `None`. If `None`, this model will not apply preprocessing, and
|
31
|
+
inputs should be preprocessed before calling the model.
|
36
32
|
|
37
33
|
Examples:
|
38
34
|
|
@@ -86,18 +82,29 @@ class DenseNetImageClassifier(ImageClassifier):
|
|
86
82
|
"""
|
87
83
|
|
88
84
|
backbone_cls = DenseNetBackbone
|
85
|
+
preprocessor_cls = DenseNetImageClassifierPreprocessor
|
89
86
|
|
90
87
|
def __init__(
|
91
88
|
self,
|
92
89
|
backbone,
|
93
90
|
num_classes,
|
94
|
-
activation=
|
95
|
-
|
96
|
-
|
91
|
+
activation=None,
|
92
|
+
pooling="avg",
|
93
|
+
preprocessor=None,
|
97
94
|
**kwargs,
|
98
95
|
):
|
99
96
|
# === Layers ===
|
100
97
|
self.backbone = backbone
|
98
|
+
self.preprocessor = preprocessor
|
99
|
+
if pooling == "avg":
|
100
|
+
self.pooler = keras.layers.GlobalAveragePooling2D()
|
101
|
+
elif pooling == "max":
|
102
|
+
self.pooler = keras.layers.GlobalMaxPooling2D()
|
103
|
+
else:
|
104
|
+
raise ValueError(
|
105
|
+
"Unknown `pooling` type. Polling should be either `'avg'` or "
|
106
|
+
f"`'max'`. Received: pooling={pooling}."
|
107
|
+
)
|
101
108
|
self.output_dense = keras.layers.Dense(
|
102
109
|
num_classes,
|
103
110
|
activation=activation,
|
@@ -107,6 +114,7 @@ class DenseNetImageClassifier(ImageClassifier):
|
|
107
114
|
# === Functional Model ===
|
108
115
|
inputs = self.backbone.input
|
109
116
|
x = self.backbone(inputs)
|
117
|
+
x = self.pooler(x)
|
110
118
|
outputs = self.output_dense(x)
|
111
119
|
super().__init__(
|
112
120
|
inputs=inputs,
|
@@ -117,6 +125,7 @@ class DenseNetImageClassifier(ImageClassifier):
|
|
117
125
|
# === Config ===
|
118
126
|
self.num_classes = num_classes
|
119
127
|
self.activation = activation
|
128
|
+
self.pooling = pooling
|
120
129
|
|
121
130
|
def get_config(self):
|
122
131
|
# Backbone serialized in `super`
|
@@ -125,6 +134,7 @@ class DenseNetImageClassifier(ImageClassifier):
|
|
125
134
|
{
|
126
135
|
"num_classes": self.num_classes,
|
127
136
|
"activation": self.activation,
|
137
|
+
"pooling": self.pooling,
|
128
138
|
}
|
129
139
|
)
|
130
140
|
return config
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright 2024 The KerasHub 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.
|
14
|
+
from keras_hub.src.api_export import keras_hub_export
|
15
|
+
from keras_hub.src.models.densenet.densenet_backbone import DenseNetBackbone
|
16
|
+
from keras_hub.src.models.densenet.densenet_image_converter import (
|
17
|
+
DenseNetImageConverter,
|
18
|
+
)
|
19
|
+
from keras_hub.src.models.image_classifier_preprocessor import (
|
20
|
+
ImageClassifierPreprocessor,
|
21
|
+
)
|
22
|
+
|
23
|
+
|
24
|
+
@keras_hub_export("keras_hub.models.DenseNetImageClassifierPreprocessor")
|
25
|
+
class DenseNetImageClassifierPreprocessor(ImageClassifierPreprocessor):
|
26
|
+
backbone_cls = DenseNetBackbone
|
27
|
+
image_converter_cls = DenseNetImageConverter
|
keras_hub/src/models/{stable_diffusion_v3/__init__.py → densenet/densenet_image_converter.py}
RENAMED
@@ -11,3 +11,13 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
+
from keras_hub.src.api_export import keras_hub_export
|
15
|
+
from keras_hub.src.layers.preprocessing.resizing_image_converter import (
|
16
|
+
ResizingImageConverter,
|
17
|
+
)
|
18
|
+
from keras_hub.src.models.densenet.densenet_backbone import DenseNetBackbone
|
19
|
+
|
20
|
+
|
21
|
+
@keras_hub_export("keras_hub.layers.DenseNetImageConverter")
|
22
|
+
class DenseNetImageConverter(ResizingImageConverter):
|
23
|
+
backbone_cls = DenseNetBackbone
|