Package: kimm
Keras Image ModelsIntroductionInstallationQuickstartImage classification with ImageNet weightsAn end-to-end fine-tuning example: cats vs. dogs datasetGrad-CAMModel ZooLicenseAcknowledgementsIntroductionKerasImageModels (kimm) is a collection of image models, blocks and layers written in Keras 3. The goal is to offer SOTA models with pretrained weights in a user-friendly manner.KIMMis:🚀 A model zoo where almost all models come withpre-trained weights on ImageNet.[!NOTE]
The accuracy of the converted models can be found atresults-imagenet.csv (timm)andhttps://keras.io/api/applications/ (keras),
and the numerical differences of the converted models can be verified intools/convert_*.py.✨ Exposing a common API identical to offcialkeras.applications.*.model=kimm.models.RegNetY002(input_tensor:keras.KerasTensor=None,input_shape:typing.Optional[typing.Sequence[int]]=None,include_preprocessing:bool=True,include_top:bool=True,pooling:typing.Optional[str]=None,dropout_rate:float=0.0,classes:int=1000,classifier_activation:str="softmax",weights:typing.Optional[str]="imagenet",name:str="RegNetY002",)🔥 Integrated withfeature extractioncapability.model=kimm.models.ConvNeXtAtto(feature_extractor=True)x=keras.random.uniform([1,224,224,3])y=model.predict(x)# y becomes a dictfork,viny.items():print(k,v.shape)🧰 Providing APIs to export models to.tfliteand.onnx.# tensorflow backendkeras.backend.set_image_data_format("channels_last")model=kimm.models.MobileNetV3W050Small()kimm.export.export_tflite(model,[224,224,3],"model.tflite")# torch backendkeras.backend.set_image_data_format("channels_first")model=kimm.models.MobileNetV3W050Small()kimm.export.export_onnx(model,[3,224,224],"model.onnx")[!IMPORTANT]kimm.export.export_tfliteis currently restricted totensorflowbackend andchannels_last.kimm.export.export_onnxis currently restricted totorchbackend andchannels_first.🔧 Supporting thereparameterizationtechnique.model=kimm.models.RepVGGA0()reparameterized_model=kimm.utils.get_reparameterized_model(model)# or# reparameterized_model = model.get_reparameterized_model()model.summary()# Total params: 9,132,616 (34.84 MB)reparameterized_model.summary()# Total params: 8,309,384 (31.70 MB)y1=model.predict(x)y2=reparameterized_model.predict(x)np.testing.assert_allclose(y1,y2,atol=1e-5)Installationpipinstallkeraskimm-UQuickstartImage classification using the model pretrained on ImageNetimportkerasfromkerasimportopsfromkerasimportutilsfromkeras.applications.imagenet_utilsimportdecode_predictionsimportkimm# Use `kimm.list_models` to get the list of available modelsprint(kimm.list_models())# Specify the name and other arguments to filter the resultprint(kimm.list_models("vision_transformer",weights="imagenet"))# fuzzy search# Initialize the model with pretrained weightsmodel=kimm.models.VisionTransformerTiny16()image_size=(model._default_size,model._default_size)# Load an image as the model inputimage_path=keras.utils.get_file("african_elephant.jpg","https://i.imgur.com/Bvro0YD.png")image=utils.load_img(image_path,target_size=image_size)image=utils.img_to_array(image)x=ops.convert_to_tensor(image)x=ops.expand_dims(x,axis=0)# Predictpreds=model.predict(x)print("Predicted:",decode_predictions(preds,top=3)[0])['ConvMixer1024D20','ConvMixer1536D20','ConvMixer736D32','ConvNeXtAtto',...]['VisionTransformerBase16','VisionTransformerBase32','VisionTransformerSmall16',...]1/1━━━━━━━━━━━━━━━━━━━━1s1s/step
Predicted:[('n02504458','African_elephant',0.6895825),('n01871265','tusker',0.17934209),('n02504013','Indian_elephant',0.12927249)]An end-to-end example: fine-tuning an image classification model on a cats vs. dogs datasetUsingkimm.models.EfficientNetLiteB0:Reference:Transfer learning & fine-tuning (keras.io)Grad-CAMUsingkimm.models.MobileViTS:Reference:Grad-CAM class activation visualization (keras.io)Model ZooModelPaperWeights are ported fromAPIConvMixerICLR 2022 Submissiontimmkimm.models.ConvMixer*ConvNeXtCVPR 2022timmkimm.models.ConvNeXt*DenseNetCVPR 2017timmkimm.models.DenseNet*EfficientNetICML 2019timmkimm.models.EfficientNet*EfficientNetLiteICML 2019timmkimm.models.EfficientNetLite*EfficientNetV2ICML 2021timmkimm.models.EfficientNetV2*GhostNetCVPR 2020timmkimm.models.GhostNet*GhostNetV2NeurIPS 2022timmkimm.models.GhostNetV2*InceptionNeXtarXiv 2023timmkimm.models.InceptionNeXt*InceptionV3CVPR 2016timmkimm.models.InceptionV3LCNetarXiv 2021timmkimm.models.LCNet*MobileNetV2CVPR 2018timmkimm.models.MobileNetV2*MobileNetV3ICCV 2019timmkimm.models.MobileNetV3*MobileOneCVPR 2023timmkimm.models.MobileOne*MobileViTICLR 2022timmkimm.models.MobileViT*MobileViTV2arXiv 2022timmkimm.models.MobileViTV2*RegNetCVPR 2020timmkimm.models.RegNet*RepVGGCVPR 2021timmkimm.models.RepVGG*ResNetCVPR 2015timmkimm.models.ResNet*TinyNetNeurIPS 2020timmkimm.models.TinyNet*VGGICLR 2015timmkimm.models.VGG*ViTICLR 2021timmkimm.models.VisionTransformer*XceptionCVPR 2017keraskimm.models.XceptionThe export scripts can be found intools/convert_*.py.LicensePlease refer totimmas this project is built upon it.kimmCodeThe code here is licensed Apache 2.0.AcknowledgementsThanks for these awesome projects that were used inkimmhttps://github.com/keras-team/kerashttps://github.com/huggingface/pytorch-image-modelsCitingBibTeX@misc{rw2019timm,author={RossWightman},title={PyTorchImageModels},year={2019},publisher={GitHub},journal={GitHubrepository},doi={10.5281/zenodo.4414861},howpublished={\url{https://github.com/rwightman/pytorch-image-models}}}@misc{hy2024kimm,author={HongyuChiu},title={KerasImageModels},year={2024},publisher={GitHub},journal={GitHubrepository},howpublished={\url{https://github.com/james77777778/kimm}}}