{"id":22111719,"url":"https://github.com/agentmaker/paddle-clip","last_synced_at":"2025-07-25T07:32:08.600Z","repository":{"id":112830270,"uuid":"345518627","full_name":"AgentMaker/Paddle-CLIP","owner":"AgentMaker","description":"A PaddlePaddle version implementation of CLIP of OpenAI.","archived":false,"fork":false,"pushed_at":"2021-11-13T05:18:18.000Z","size":1597,"stargazers_count":68,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-11T11:38:14.180Z","etag":null,"topics":["clip","paddlepaddle"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AgentMaker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-03-08T03:25:24.000Z","updated_at":"2024-10-23T12:07:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"dd6bb71c-b9b2-42b2-98a1-580a3bb4a404","html_url":"https://github.com/AgentMaker/Paddle-CLIP","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/AgentMaker/Paddle-CLIP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-CLIP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-CLIP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-CLIP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-CLIP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AgentMaker","download_url":"https://codeload.github.com/AgentMaker/Paddle-CLIP/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-CLIP/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266972956,"owners_count":24014609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clip","paddlepaddle"],"created_at":"2024-12-01T10:51:27.748Z","updated_at":"2025-07-25T07:32:08.246Z","avatar_url":"https://github.com/AgentMaker.png","language":"Python","readme":"# Paddle-CLIP\n![GitHub forks](https://img.shields.io/github/forks/AgentMaker/Paddle-CLIP)\n![GitHub Repo stars](https://img.shields.io/github/stars/AgentMaker/Paddle-CLIP)\n![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/AgentMaker/Paddle-CLIP?include_prereleases)\n![GitHub](https://img.shields.io/github/license/AgentMaker/Paddle-CLIP)  \nA PaddlePaddle version implementation of CLIP of OpenAI. [【origin repo】](https://github.com/openai/CLIP/)\n\n## Install Package\n* Install by pip：\n```shell\n$ pip install paddleclip\n```\n* Install by wheel package：[【Releases Packages】](https://github.com/AgentMaker/Paddle-CLIP/releases)\n\n## Requirements\n* wget\n* ftfy\n* regex\n* paddlepaddle(cpu/gpu)\u003e=2.0.1\n\n## Quick Start\n```python\nimport paddle\nfrom PIL import Image\nfrom clip import tokenize, load_model\n\n# Load the model\nmodel, transforms = load_model('ViT_B_32', pretrained=True)\n\n# Prepare the inputs\nimage = transforms(Image.open(\"CLIP.png\")).unsqueeze(0)\ntext = tokenize([\"a diagram\", \"a dog\", \"a cat\"])\n\n# Calculate features and probability\nwith paddle.no_grad():\n    logits_per_image, logits_per_text = model(image, text)\n    probs = paddle.nn.functional.softmax(logits_per_image, axis=-1)\n    \n# Print the result\nprint(probs.numpy())\n```\n    [[0.9927937  0.00421065 0.00299568]]\n\n## Zero-Shot Prediction\n```python\nimport paddle\nfrom clip import tokenize, load_model\nfrom paddle.vision.datasets import Cifar100\n\n# Load the model\nmodel, transforms = load_model('ViT_B_32', pretrained=True)\n\n# Load the dataset\ncifar100 = Cifar100(mode='test', backend='pil')\nclasses = [\n    'apple', 'aquarium_fish', 'baby', 'bear', 'beaver', 'bed', 'bee', 'beetle', 'bicycle', 'bottle', \n    'bowl', 'boy', 'bridge', 'bus', 'butterfly', 'camel', 'can', 'castle', 'caterpillar', 'cattle', \n    'chair', 'chimpanzee', 'clock', 'cloud', 'cockroach', 'couch', 'crab', 'crocodile', 'cup', 'dinosaur', \n    'dolphin', 'elephant', 'flatfish', 'forest', 'fox', 'girl', 'hamster', 'house', 'kangaroo', 'keyboard', \n    'lamp', 'lawn_mower', 'leopard', 'lion', 'lizard', 'lobster', 'man', 'maple_tree', 'motorcycle', 'mountain', \n    'mouse', 'mushroom', 'oak_tree', 'orange', 'orchid', 'otter', 'palm_tree', 'pear', 'pickup_truck', 'pine_tree', \n    'plain', 'plate', 'poppy', 'porcupine', 'possum', 'rabbit', 'raccoon', 'ray', 'road', 'rocket', \n    'rose', 'sea', 'seal', 'shark', 'shrew', 'skunk', 'skyscraper', 'snail', 'snake', 'spider', \n    'squirrel', 'streetcar', 'sunflower', 'sweet_pepper', 'table', 'tank', 'telephone', 'television', 'tiger', 'tractor', \n    'train', 'trout', 'tulip', 'turtle', 'wardrobe', 'whale', 'willow_tree', 'wolf', 'woman', 'worm'\n]\n\n# Prepare the inputs\nimage, class_id = cifar100[3637]\nimage_input = transforms(image).unsqueeze(0)\ntext_inputs = tokenize([\"a photo of a %s\" % c for c in classes])\n\n# Calculate features\nwith paddle.no_grad():\n    image_features = model.encode_image(image_input)\n    text_features = model.encode_text(text_inputs)\n\n# Pick the top 5 most similar labels for the image\nimage_features /= image_features.norm(axis=-1, keepdim=True)\ntext_features /= text_features.norm(axis=-1, keepdim=True)\nsimilarity = (100.0 * image_features @ text_features.t())\nsimilarity = paddle.nn.functional.softmax(similarity, axis=-1)\nvalues, indices = similarity[0].topk(5)\n\n# Print the result\nfor value, index in zip(values, indices):\n    print('%s: %.02f%%' % (classes[index], value*100.))\n```\n    snake: 65.31%\n    turtle: 12.29%\n    sweet_pepper: 3.83%\n    lizard: 1.88%\n    crocodile: 1.75%\n\n## Linear-probe evaluation\n```python\nimport os\nimport paddle\nimport numpy as np\nfrom tqdm import tqdm\nfrom paddle.io import DataLoader\nfrom clip import tokenize, load_model\nfrom paddle.vision.datasets import Cifar100\nfrom sklearn.linear_model import LogisticRegression\n\n# Load the model\nmodel, transforms = load_model('ViT_B_32', pretrained=True)\n\n# Load the dataset\ntrain = Cifar100(mode='train', transform=transforms, backend='pil')\ntest = Cifar100(mode='test', transform=transforms, backend='pil')\n\n# Get features\ndef get_features(dataset):\n    all_features = []\n    all_labels = []\n    \n    with paddle.no_grad():\n        for images, labels in tqdm(DataLoader(dataset, batch_size=100)):\n            features = model.encode_image(images)\n            all_features.append(features)\n            all_labels.append(labels)\n\n    return paddle.concat(all_features).numpy(), paddle.concat(all_labels).numpy()\n\n# Calculate the image features\ntrain_features, train_labels = get_features(train)\ntest_features, test_labels = get_features(test)\n\n# Perform logistic regression\nclassifier = LogisticRegression(random_state=0, C=0.316, max_iter=1000, verbose=0)\nclassifier.fit(train_features, train_labels)\n\n# Evaluate using the logistic regression classifier\npredictions = classifier.predict(test_features)\naccuracy = np.mean((test_labels == predictions).astype(np.float)) * 100.\n\n# Print the result\nprint(f\"Accuracy = {accuracy:.3f}\")\n```\n    Accuracy = 79.900\n\n## Pretrained Models Download\n* [RN50](https://bj.bcebos.com/v1/ai-studio-online/6ffc89246e974a809e6e4b40fdb58063a112a0153e674dae8ed5b6dfe5d46d86?responseContentDisposition=attachment%3B%20filename%3DRN50.pdparams)\n* [RN50x4](https://bj.bcebos.com/v1/ai-studio-online/9f874e0174da48ffbd7c17e77b1fb278632620a9995e476ba873e334caec9037?responseContentDisposition=attachment%3B%20filename%3DRN50x4.pdparams)\n* [RN101](https://bj.bcebos.com/v1/ai-studio-online/484592d98c584785bc8f6f9f7badbf4a9fb7a96f6102470697ed974e8eeee2a9?responseContentDisposition=attachment%3B%20filename%3DRN101.pdparams)\n* [ViT_B_32](https://bj.bcebos.com/v1/ai-studio-online/eb5e4dbf1ec142caa003a27cefd510ef46a8a6c3932a4d60bfecb3f3ab746c02?responseContentDisposition=attachment%3B%20filename%3DViT-B-32.pdparams)\n\n## Contact us\nEmail : [agentmaker@163.com]()\u003cbr\u003e\nQQ Group : 1005109853\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentmaker%2Fpaddle-clip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagentmaker%2Fpaddle-clip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentmaker%2Fpaddle-clip/lists"}