Skip to content

Commit

Permalink
Fixed typos, streamlined code by removing unnecessary package imports…
Browse files Browse the repository at this point in the history
…, and adjusted optional variable handling. These changes enhance code clarity and efficiency. Related to PR #3925
  • Loading branch information
AdonaiVera authored and brimoor committed Dec 20, 2023
1 parent 8ed7260 commit 66c12ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions fiftyone/utils/open_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
|
"""
import logging
import os
from packaging.version import Version
import warnings

import eta.core.web as etaw

import fiftyone as fo
import fiftyone.core.models as fom
import fiftyone.core.utils as fou
import fiftyone.utils.torch as fout
Expand All @@ -21,13 +15,15 @@
fou.ensure_torch()
import torch

import open_clip
open_clip = fou.lazy_import(
"open_clip", callback=lambda: fou.ensure_package("open_clip_torch")
)

logger = logging.getLogger(__name__)


class TorchOpenClipModelConfig(fout.TorchImageModelConfig, fozm.HasZooModel):
"""Configuration for running a :class:`TorchCLIPModel`.
"""Configuration for running a :class:`TorchOpenClipModel`.
See :class:`fiftyone.utils.torch.TorchImageModelConfig` for additional
arguments.
Expand All @@ -36,7 +32,7 @@ class TorchOpenClipModelConfig(fout.TorchImageModelConfig, fozm.HasZooModel):
context_length: the model's context length
text_prompt: the text prompt to use, e.g., ``"A photo of"``
classes (None): a list of custom classes for zero-shot prediction
model_name_clip (None): the model to use
model_name (None): the model to use
pretrained (None): the pretrained version to use
"""

Expand All @@ -47,15 +43,17 @@ def __init__(self, d):
self.context_length = self.parse_int(d, "context_length")
self.text_prompt = self.parse_string(d, "text_prompt")

self.model_name_clip = self.parse_string(d, "model_name_clip")
self.pretrained = self.parse_string(d, "pretrained")
self.model_name_clip = self.parse_string(
d, "model_name_clip", default="ViT-B-32"
)
self.pretrained = self.parse_string(d, "pretrained", default=None)


class TorchOpenClipModel(fout.TorchImageModel, fom.PromptMixin):
"""Torch implementation of CLIP from https://github.com/mlfoundations/open_clip.
Args:
config: a :class:`TorchOpenClipPModelConfig`
config: a :class:`TorchOpenClipModelConfig`
"""

def __init__(self, config):
Expand Down
2 changes: 1 addition & 1 deletion fiftyone/zoo/models/manifest-torch.json
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@
"date_added": "2020-12-11 13:45:51"
},
{
"base_name": "open-clip",
"base_name": "open-clip-torch",
"base_filename": "",
"version": null,
"description": "OPEN CLIP text/image encoder from `Learning Transferable Visual Models From Natural Language Supervision <https://arxiv.org/abs/2103.00020>`_ trained on 400M text-image pairs",
Expand Down

0 comments on commit 66c12ab

Please sign in to comment.