init
162
.gitignore
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
||||
.pdm.toml
|
||||
.pdm-python
|
||||
.pdm-build/
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
.idea/
|
||||
101
Adapter.py
Normal file
@@ -0,0 +1,101 @@
|
||||
import torch.nn as nn
|
||||
from clip import clip
|
||||
import torch
|
||||
|
||||
|
||||
|
||||
class Weight_Adapter(nn.Module):
|
||||
def __init__(self, args, classnames,init_weights):
|
||||
super().__init__()
|
||||
self.classnames = classnames
|
||||
if args.name in ["ViT-B/16", "ViT-B/32"]:
|
||||
n_input = 512
|
||||
elif args.name in ["RN50", "RN50x16"]:
|
||||
n_input = 1024
|
||||
n_output = 2 * len(classnames)
|
||||
self.linear = nn.Linear(n_input, n_output, bias=False)
|
||||
self.linear.weight.data = init_weights # Initialize linear layer weights
|
||||
|
||||
def forward(self, x):
|
||||
x = self.linear(x)
|
||||
return x
|
||||
class Classifier(nn.Module):
|
||||
def __init__(self, args, classnames,init_weights):
|
||||
super().__init__()
|
||||
self.classnames = classnames
|
||||
if args.name in ["ViT-B/16", "ViT-B/32"]:
|
||||
n_input = 512
|
||||
elif args.name in ["RN50", "RN50x16"]:
|
||||
n_input = 1024
|
||||
n_output = len(classnames)
|
||||
self.linear = nn.Linear(n_input, n_output, bias=False)
|
||||
self.linear.weight.data = init_weights # Initialize linear layer weights
|
||||
|
||||
def forward(self, x):
|
||||
x = self.linear(x)
|
||||
return x
|
||||
|
||||
class Adapter(nn.Module):
|
||||
def __init__(self, args, classnames,init_weights):
|
||||
super().__init__()
|
||||
self.classnames = classnames
|
||||
if args.name in ["ViT-B/16", "ViT-B/32"]:
|
||||
n_input = 512
|
||||
elif args.name in ["RN50", "RN50x16"]:
|
||||
n_input = 1024
|
||||
n_output = len(classnames)
|
||||
self.linear = nn.Linear(n_input, n_output, bias=False)
|
||||
self.linear.weight.data = init_weights # Initialize linear layer weights
|
||||
|
||||
def forward(self, x):
|
||||
x = self.linear(x)
|
||||
return x
|
||||
|
||||
class Linear(nn.Module):
|
||||
def __init__(self, args):
|
||||
super().__init__()
|
||||
if args.name in ["ViT-B/16", "ViT-B/32"]:
|
||||
n_input = 512
|
||||
elif args.name in ["RN50", "RN50x16"]:
|
||||
n_input = 1024
|
||||
self.linear = nn.Linear(n_input, n_input, bias=False)
|
||||
|
||||
def forward(self, x):
|
||||
x = self.linear(x)
|
||||
return x
|
||||
|
||||
class Res_Adapter(nn.Module):
|
||||
def __init__(self, n_input, ):
|
||||
super().__init__()
|
||||
self.residual_ratio = 0.5
|
||||
self.fc = nn.Sequential(
|
||||
nn.Linear(n_input, n_input // 4, bias=False),
|
||||
nn.ReLU(inplace=True),
|
||||
nn.Linear(n_input // 4, n_input, bias=False),
|
||||
nn.ReLU(inplace=True)
|
||||
|
||||
)
|
||||
|
||||
def forward(self, x):
|
||||
a = self.fc(x)
|
||||
x = self.residual_ratio * a + (1 - self.residual_ratio) * x
|
||||
|
||||
return x
|
||||
|
||||
def all_classifier(classnames, templates, model):
|
||||
with torch.no_grad():
|
||||
zeroshot_weights = []
|
||||
for classname in classnames:
|
||||
classname = classname.replace('_', ' ')
|
||||
texts = [template.format(classname) for template in templates] # format with class
|
||||
texts = clip.tokenize(texts).cuda() # tokenizeclip.tokenize向量化文字
|
||||
class_embeddings = model.encode_text(texts) # embed with text encoder
|
||||
class_embeddings /= class_embeddings.norm(dim=-1, keepdim=True)
|
||||
class_embedding = class_embeddings.mean(dim=0)
|
||||
class_embedding /= class_embedding.norm()
|
||||
zeroshot_weights.append(class_embedding)
|
||||
|
||||
zeroshot_weights = torch.stack(zeroshot_weights, dim=1).cuda()
|
||||
return zeroshot_weights
|
||||
|
||||
|
||||
BIN
Average.png
Normal file
|
After Width: | Height: | Size: 534 KiB |
BIN
Caltech101.png
Normal file
|
After Width: | Height: | Size: 385 KiB |
BIN
EuroSAT.png
Normal file
|
After Width: | Height: | Size: 331 KiB |
BIN
FGVCAircraft.png
Normal file
|
After Width: | Height: | Size: 379 KiB |
BIN
Flowers102.png
Normal file
|
After Width: | Height: | Size: 361 KiB |
BIN
Food101.png
Normal file
|
After Width: | Height: | Size: 321 KiB |
BIN
GTP-CLIP_ACC.jpg
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
ImageNet.png
Normal file
|
After Width: | Height: | Size: 348 KiB |
BIN
OxfordPets.png
Normal file
|
After Width: | Height: | Size: 384 KiB |
BIN
SUN397.png
Normal file
|
After Width: | Height: | Size: 393 KiB |
BIN
StanfordCars.png
Normal file
|
After Width: | Height: | Size: 410 KiB |
BIN
UCF101.png
Normal file
|
After Width: | Height: | Size: 374 KiB |
71112
checkpoints/log.txt
Normal file
1
clip/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .clip import *
|
||||
BIN
clip/bpe_simple_vocab_16e6.txt.gz
Normal file
220
clip/clip.py
Normal file
@@ -0,0 +1,220 @@
|
||||
import hashlib
|
||||
import os
|
||||
import urllib
|
||||
import warnings
|
||||
from typing import Union, List
|
||||
|
||||
import torch
|
||||
from PIL import Image
|
||||
from torchvision.transforms import Compose, Resize, CenterCrop, ToTensor, Normalize
|
||||
from tqdm import tqdm
|
||||
|
||||
from .model import build_model
|
||||
from .simple_tokenizer import SimpleTokenizer as _Tokenizer
|
||||
|
||||
try:
|
||||
from torchvision.transforms import InterpolationMode
|
||||
|
||||
BICUBIC = InterpolationMode.BICUBIC
|
||||
except ImportError:
|
||||
BICUBIC = Image.BICUBIC
|
||||
|
||||
if torch.__version__.split(".") < ["1", "7", "1"]:
|
||||
warnings.warn("PyTorch version 1.7.1 or higher is recommended")
|
||||
|
||||
__all__ = ["available_models", "load", "tokenize"]
|
||||
_tokenizer = _Tokenizer()
|
||||
|
||||
_MODELS = {
|
||||
"RN50": "https://openaipublic.azureedge.net/clip/models/afeb0e10f9e5a86da6080e35cf09123aca3b358a0c3e3b6c78a7b63bc04b6762/RN50.pt",
|
||||
"RN101": "https://openaipublic.azureedge.net/clip/models/8fa8567bab74a42d41c5915025a8e4538c3bdbe8804a470a72f30b0d94fab599/RN101.pt",
|
||||
"RN50x4": "https://openaipublic.azureedge.net/clip/models/7e526bd135e493cef0776de27d5f42653e6b4c8bf9e0f653bb11773263205fdd/RN50x4.pt",
|
||||
"RN50x16": "https://openaipublic.azureedge.net/clip/models/52378b407f34354e150460fe41077663dd5b39c54cd0bfd2b27167a4a06ec9aa/RN50x16.pt",
|
||||
"ViT-B/32": "https://openaipublic.azureedge.net/clip/models/40d365715913c9da98579312b702a82c18be219cc2a73407c4526f58eba950af/ViT-B-32.pt",
|
||||
"ViT-B/16": "https://openaipublic.azureedge.net/clip/models/5806e77cd80f8b59890b7e101eabd078d9fb84e6937f9e85e4ecb61988df416f/ViT-B-16.pt",
|
||||
}
|
||||
|
||||
|
||||
def _download(url: str, root: str = os.path.expanduser("~/.cache/clip")):
|
||||
os.makedirs(root, exist_ok=True)
|
||||
filename = os.path.basename(url)
|
||||
|
||||
expected_sha256 = url.split("/")[-2]
|
||||
download_target = os.path.join(root, filename)
|
||||
|
||||
if os.path.exists(download_target) and not os.path.isfile(download_target):
|
||||
raise RuntimeError(f"{download_target} exists and is not a regular file")
|
||||
|
||||
if os.path.isfile(download_target):
|
||||
if hashlib.sha256(open(download_target, "rb").read()).hexdigest() == expected_sha256:
|
||||
return download_target
|
||||
else:
|
||||
warnings.warn(f"{download_target} exists, but the SHA256 checksum does not match; re-downloading the file")
|
||||
|
||||
with urllib.request.urlopen(url) as source, open(download_target, "wb") as output:
|
||||
with tqdm(total=int(source.info().get("Content-Length")), ncols=80, unit='iB', unit_scale=True) as loop:
|
||||
while True:
|
||||
buffer = source.read(8192)
|
||||
if not buffer:
|
||||
break
|
||||
|
||||
output.write(buffer)
|
||||
loop.update(len(buffer))
|
||||
|
||||
if hashlib.sha256(open(download_target, "rb").read()).hexdigest() != expected_sha256:
|
||||
raise RuntimeError(f"Model has been downloaded but the SHA256 checksum does not not match")
|
||||
|
||||
return download_target
|
||||
|
||||
|
||||
def _transform(n_px):
|
||||
return Compose([
|
||||
Resize(n_px, interpolation=BICUBIC),
|
||||
CenterCrop(n_px),
|
||||
lambda image: image.convert("RGB"),
|
||||
ToTensor(),
|
||||
Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
|
||||
])
|
||||
|
||||
|
||||
def available_models() -> List[str]:
|
||||
"""Returns the names of available CLIP models"""
|
||||
return list(_MODELS.keys())
|
||||
|
||||
|
||||
def load(name: str, device: Union[str, torch.device] = "cuda" if torch.cuda.is_available() else "cpu", jit=False):
|
||||
"""Load a CLIP model
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
A model name listed by `clip.available_models()`, or the path to a model checkpoint containing the state_dict
|
||||
|
||||
device : Union[str, torch.device]
|
||||
The device to put the loaded model
|
||||
|
||||
jit : bool
|
||||
Whether to load the optimized JIT model or more hackable non-JIT model (default).
|
||||
|
||||
Returns
|
||||
-------
|
||||
model : torch.nn.Module
|
||||
The CLIP model
|
||||
|
||||
preprocess : Callable[[PIL.Image], torch.Tensor]
|
||||
A torchvision transform that converts a PIL image into a tensor that the returned model can take as its input
|
||||
"""
|
||||
if name in _MODELS:
|
||||
model_path = _download(_MODELS[name])
|
||||
elif os.path.isfile(name):
|
||||
model_path = name
|
||||
else:
|
||||
raise RuntimeError(f"Model {name} not found; available models = {available_models()}")
|
||||
|
||||
try:
|
||||
# loading JIT archive
|
||||
model = torch.jit.load(model_path, map_location=device if jit else "cpu").eval()
|
||||
state_dict = None
|
||||
except RuntimeError:
|
||||
# loading saved state dict
|
||||
if jit:
|
||||
warnings.warn(f"File {model_path} is not a JIT archive. Loading as a state dict instead")
|
||||
jit = False
|
||||
state_dict = torch.load(model_path, map_location="cpu")
|
||||
|
||||
if not jit:
|
||||
model = build_model(state_dict or model.state_dict()).to(device)
|
||||
if str(device) == "cpu":
|
||||
model.float()
|
||||
return model, _transform(model.visual.input_resolution)
|
||||
|
||||
# patch the device names
|
||||
device_holder = torch.jit.trace(lambda: torch.ones([]).to(torch.device(device)), example_inputs=[])
|
||||
device_node = [n for n in device_holder.graph.findAllNodes("prim::Constant") if "Device" in repr(n)][-1]
|
||||
|
||||
def patch_device(module):
|
||||
try:
|
||||
graphs = [module.graph] if hasattr(module, "graph") else []
|
||||
except RuntimeError:
|
||||
graphs = []
|
||||
|
||||
if hasattr(module, "forward1"):
|
||||
graphs.append(module.forward1.graph)
|
||||
|
||||
for graph in graphs:
|
||||
for node in graph.findAllNodes("prim::Constant"):
|
||||
if "value" in node.attributeNames() and str(node["value"]).startswith("cuda"):
|
||||
node.copyAttributes(device_node)
|
||||
|
||||
model.apply(patch_device)
|
||||
patch_device(model.encode_image)
|
||||
patch_device(model.encode_text)
|
||||
|
||||
# patch dtype to float32 on CPU
|
||||
if str(device) == "cpu":
|
||||
float_holder = torch.jit.trace(lambda: torch.ones([]).float(), example_inputs=[])
|
||||
float_input = list(float_holder.graph.findNode("aten::to").inputs())[1]
|
||||
float_node = float_input.node()
|
||||
|
||||
def patch_float(module):
|
||||
try:
|
||||
graphs = [module.graph] if hasattr(module, "graph") else []
|
||||
except RuntimeError:
|
||||
graphs = []
|
||||
|
||||
if hasattr(module, "forward1"):
|
||||
graphs.append(module.forward1.graph)
|
||||
|
||||
for graph in graphs:
|
||||
for node in graph.findAllNodes("aten::to"):
|
||||
inputs = list(node.inputs())
|
||||
for i in [1, 2]: # dtype can be the second or third argument to aten::to()
|
||||
if inputs[i].node()["value"] == 5:
|
||||
inputs[i].node().copyAttributes(float_node)
|
||||
|
||||
model.apply(patch_float)
|
||||
patch_float(model.encode_image)
|
||||
patch_float(model.encode_text)
|
||||
|
||||
model.float()
|
||||
|
||||
return model, _transform(model.input_resolution.item())
|
||||
|
||||
|
||||
def tokenize(texts: Union[str, List[str]], context_length: int = 77, truncate: bool = False) -> torch.LongTensor:
|
||||
"""
|
||||
Returns the tokenized representation of given input string(s)
|
||||
|
||||
Parameters
|
||||
----------
|
||||
texts : Union[str, List[str]]
|
||||
An input string or a list of input strings to tokenize
|
||||
|
||||
context_length : int
|
||||
The context length to use; all CLIP models use 77 as the context length
|
||||
|
||||
truncate: bool
|
||||
Whether to truncate the text in case its encoding is longer than the context length
|
||||
|
||||
Returns
|
||||
-------
|
||||
A two-dimensional tensor containing the resulting tokens, shape = [number of input strings, context_length]
|
||||
"""
|
||||
if isinstance(texts, str):
|
||||
texts = [texts]
|
||||
|
||||
sot_token = _tokenizer.encoder["<|startoftext|>"]
|
||||
eot_token = _tokenizer.encoder["<|endoftext|>"]
|
||||
all_tokens = [[sot_token] + _tokenizer.encode(text) + [eot_token] for text in texts]
|
||||
result = torch.zeros(len(all_tokens), context_length, dtype=torch.long)
|
||||
|
||||
for i, tokens in enumerate(all_tokens):
|
||||
if len(tokens) > context_length:
|
||||
if truncate:
|
||||
tokens = tokens[:context_length]
|
||||
tokens[-1] = eot_token
|
||||
else:
|
||||
raise RuntimeError(f"Input {texts[i]} is too long for context length {context_length}")
|
||||
result[i, :len(tokens)] = torch.tensor(tokens)
|
||||
|
||||
return result
|
||||
436
clip/model.py
Normal file
@@ -0,0 +1,436 @@
|
||||
from collections import OrderedDict
|
||||
from typing import Tuple, Union
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
from torch import nn
|
||||
|
||||
|
||||
class Bottleneck(nn.Module):
|
||||
expansion = 4
|
||||
|
||||
def __init__(self, inplanes, planes, stride=1):
|
||||
super().__init__()
|
||||
|
||||
# all conv layers have stride 1. an avgpool is performed after the second convolution when stride > 1
|
||||
self.conv1 = nn.Conv2d(inplanes, planes, 1, bias=False)
|
||||
self.bn1 = nn.BatchNorm2d(planes)
|
||||
|
||||
self.conv2 = nn.Conv2d(planes, planes, 3, padding=1, bias=False)
|
||||
self.bn2 = nn.BatchNorm2d(planes)
|
||||
|
||||
self.avgpool = nn.AvgPool2d(stride) if stride > 1 else nn.Identity()
|
||||
|
||||
self.conv3 = nn.Conv2d(planes, planes * self.expansion, 1, bias=False)
|
||||
self.bn3 = nn.BatchNorm2d(planes * self.expansion)
|
||||
|
||||
self.relu = nn.ReLU()
|
||||
self.downsample = None
|
||||
self.stride = stride
|
||||
|
||||
if stride > 1 or inplanes != planes * Bottleneck.expansion:
|
||||
# downsampling layer is prepended with an avgpool, and the subsequent convolution has stride 1
|
||||
self.downsample = nn.Sequential(OrderedDict([
|
||||
("-1", nn.AvgPool2d(stride)),
|
||||
("0", nn.Conv2d(inplanes, planes * self.expansion, 1, stride=1, bias=False)),
|
||||
("1", nn.BatchNorm2d(planes * self.expansion))
|
||||
]))
|
||||
|
||||
def forward(self, x: torch.Tensor):
|
||||
identity = x
|
||||
|
||||
out = self.relu(self.bn1(self.conv1(x)))
|
||||
out = self.relu(self.bn2(self.conv2(out)))
|
||||
out = self.avgpool(out)
|
||||
out = self.bn3(self.conv3(out))
|
||||
|
||||
if self.downsample is not None:
|
||||
identity = self.downsample(x)
|
||||
|
||||
out += identity
|
||||
out = self.relu(out)
|
||||
return out
|
||||
|
||||
|
||||
class AttentionPool2d(nn.Module):
|
||||
def __init__(self, spacial_dim: int, embed_dim: int, num_heads: int, output_dim: int = None):
|
||||
super().__init__()
|
||||
self.positional_embedding = nn.Parameter(torch.randn(spacial_dim ** 2 + 1, embed_dim) / embed_dim ** 0.5)
|
||||
self.k_proj = nn.Linear(embed_dim, embed_dim)
|
||||
self.q_proj = nn.Linear(embed_dim, embed_dim)
|
||||
self.v_proj = nn.Linear(embed_dim, embed_dim)
|
||||
self.c_proj = nn.Linear(embed_dim, output_dim or embed_dim)
|
||||
self.num_heads = num_heads
|
||||
|
||||
def forward(self, x):
|
||||
x = x.reshape(x.shape[0], x.shape[1], x.shape[2] * x.shape[3]).permute(2, 0, 1) # NCHW -> (HW)NC
|
||||
x = torch.cat([x.mean(dim=0, keepdim=True), x], dim=0) # (HW+1)NC
|
||||
x = x + self.positional_embedding[:, None, :].to(x.dtype) # (HW+1)NC
|
||||
x, _ = F.multi_head_attention_forward(
|
||||
query=x, key=x, value=x,
|
||||
embed_dim_to_check=x.shape[-1],
|
||||
num_heads=self.num_heads,
|
||||
q_proj_weight=self.q_proj.weight,
|
||||
k_proj_weight=self.k_proj.weight,
|
||||
v_proj_weight=self.v_proj.weight,
|
||||
in_proj_weight=None,
|
||||
in_proj_bias=torch.cat([self.q_proj.bias, self.k_proj.bias, self.v_proj.bias]),
|
||||
bias_k=None,
|
||||
bias_v=None,
|
||||
add_zero_attn=False,
|
||||
dropout_p=0,
|
||||
out_proj_weight=self.c_proj.weight,
|
||||
out_proj_bias=self.c_proj.bias,
|
||||
use_separate_proj_weight=True,
|
||||
training=self.training,
|
||||
need_weights=False
|
||||
)
|
||||
|
||||
return x[0]
|
||||
|
||||
|
||||
class ModifiedResNet(nn.Module):
|
||||
"""
|
||||
A ResNet class that is similar to torchvision's but contains the following changes:
|
||||
- There are now 3 "stem" convolutions as opposed to 1, with an average pool instead of a max pool.
|
||||
- Performs anti-aliasing strided convolutions, where an avgpool is prepended to convolutions with stride > 1
|
||||
- The final pooling layer is a QKV attention instead of an average pool
|
||||
"""
|
||||
|
||||
def __init__(self, layers, output_dim, heads, input_resolution=224, width=64):
|
||||
super().__init__()
|
||||
self.output_dim = output_dim
|
||||
self.input_resolution = input_resolution
|
||||
|
||||
# the 3-layer stem
|
||||
self.conv1 = nn.Conv2d(3, width // 2, kernel_size=3, stride=2, padding=1, bias=False)
|
||||
self.bn1 = nn.BatchNorm2d(width // 2)
|
||||
self.conv2 = nn.Conv2d(width // 2, width // 2, kernel_size=3, padding=1, bias=False)
|
||||
self.bn2 = nn.BatchNorm2d(width // 2)
|
||||
self.conv3 = nn.Conv2d(width // 2, width, kernel_size=3, padding=1, bias=False)
|
||||
self.bn3 = nn.BatchNorm2d(width)
|
||||
self.avgpool = nn.AvgPool2d(2)
|
||||
self.relu = nn.ReLU()
|
||||
|
||||
# residual layers
|
||||
self._inplanes = width # this is a *mutable* variable used during construction
|
||||
self.layer1 = self._make_layer(width, layers[0])
|
||||
self.layer2 = self._make_layer(width * 2, layers[1], stride=2)
|
||||
self.layer3 = self._make_layer(width * 4, layers[2], stride=2)
|
||||
self.layer4 = self._make_layer(width * 8, layers[3], stride=2)
|
||||
|
||||
embed_dim = width * 32 # the ResNet feature dimension
|
||||
self.attnpool = AttentionPool2d(input_resolution // 32, embed_dim, heads, output_dim)
|
||||
|
||||
def _make_layer(self, planes, blocks, stride=1):
|
||||
layers = [Bottleneck(self._inplanes, planes, stride)]
|
||||
|
||||
self._inplanes = planes * Bottleneck.expansion
|
||||
for _ in range(1, blocks):
|
||||
layers.append(Bottleneck(self._inplanes, planes))
|
||||
|
||||
return nn.Sequential(*layers)
|
||||
|
||||
def forward(self, x):
|
||||
def stem(x):
|
||||
for conv, bn in [(self.conv1, self.bn1), (self.conv2, self.bn2), (self.conv3, self.bn3)]:
|
||||
x = self.relu(bn(conv(x)))
|
||||
x = self.avgpool(x)
|
||||
return x
|
||||
|
||||
x = x.type(self.conv1.weight.dtype)
|
||||
x = stem(x)
|
||||
x = self.layer1(x)
|
||||
x = self.layer2(x)
|
||||
x = self.layer3(x)
|
||||
x = self.layer4(x)
|
||||
x = self.attnpool(x)
|
||||
|
||||
return x
|
||||
|
||||
|
||||
class LayerNorm(nn.LayerNorm):
|
||||
"""Subclass torch's LayerNorm to handle fp16."""
|
||||
|
||||
def forward(self, x: torch.Tensor):
|
||||
orig_type = x.dtype
|
||||
ret = super().forward(x.type(torch.float32))
|
||||
return ret.type(orig_type)
|
||||
|
||||
|
||||
class QuickGELU(nn.Module):
|
||||
def forward(self, x: torch.Tensor):
|
||||
return x * torch.sigmoid(1.702 * x)
|
||||
|
||||
|
||||
class ResidualAttentionBlock(nn.Module):
|
||||
def __init__(self, d_model: int, n_head: int, attn_mask: torch.Tensor = None):
|
||||
super().__init__()
|
||||
|
||||
self.attn = nn.MultiheadAttention(d_model, n_head)
|
||||
self.ln_1 = LayerNorm(d_model)
|
||||
self.mlp = nn.Sequential(OrderedDict([
|
||||
("c_fc", nn.Linear(d_model, d_model * 4)),
|
||||
("gelu", QuickGELU()),
|
||||
("c_proj", nn.Linear(d_model * 4, d_model))
|
||||
]))
|
||||
self.ln_2 = LayerNorm(d_model)
|
||||
self.attn_mask = attn_mask
|
||||
|
||||
def attention(self, x: torch.Tensor):
|
||||
self.attn_mask = self.attn_mask.to(dtype=x.dtype, device=x.device) if self.attn_mask is not None else None
|
||||
return self.attn(x, x, x, need_weights=False, attn_mask=self.attn_mask)[0]
|
||||
|
||||
def forward(self, x: torch.Tensor):
|
||||
x = x + self.attention(self.ln_1(x))
|
||||
x = x + self.mlp(self.ln_2(x))
|
||||
return x
|
||||
|
||||
|
||||
class Transformer(nn.Module):
|
||||
def __init__(self, width: int, layers: int, heads: int, attn_mask: torch.Tensor = None):
|
||||
super().__init__()
|
||||
self.width = width
|
||||
self.layers = layers
|
||||
self.resblocks = nn.Sequential(*[ResidualAttentionBlock(width, heads, attn_mask) for _ in range(layers)])
|
||||
|
||||
def forward(self, x: torch.Tensor):
|
||||
return self.resblocks(x)
|
||||
|
||||
|
||||
class VisionTransformer(nn.Module):
|
||||
def __init__(self, input_resolution: int, patch_size: int, width: int, layers: int, heads: int, output_dim: int):
|
||||
super().__init__()
|
||||
self.input_resolution = input_resolution
|
||||
self.output_dim = output_dim
|
||||
self.conv1 = nn.Conv2d(in_channels=3, out_channels=width, kernel_size=patch_size, stride=patch_size, bias=False)
|
||||
|
||||
scale = width ** -0.5
|
||||
self.class_embedding = nn.Parameter(scale * torch.randn(width))
|
||||
self.positional_embedding = nn.Parameter(scale * torch.randn((input_resolution // patch_size) ** 2 + 1, width))
|
||||
self.ln_pre = LayerNorm(width)
|
||||
|
||||
self.transformer = Transformer(width, layers, heads)
|
||||
|
||||
self.ln_post = LayerNorm(width)
|
||||
self.proj = nn.Parameter(scale * torch.randn(width, output_dim))
|
||||
|
||||
def forward(self, x: torch.Tensor):
|
||||
x = self.conv1(x) # shape = [*, width, grid, grid]
|
||||
x = x.reshape(x.shape[0], x.shape[1], -1) # shape = [*, width, grid ** 2]
|
||||
x = x.permute(0, 2, 1) # shape = [*, grid ** 2, width]
|
||||
x = torch.cat(
|
||||
[self.class_embedding.to(x.dtype) + torch.zeros(x.shape[0], 1, x.shape[-1], dtype=x.dtype, device=x.device),
|
||||
x], dim=1) # shape = [*, grid ** 2 + 1, width]
|
||||
x = x + self.positional_embedding.to(x.dtype)
|
||||
x = self.ln_pre(x)
|
||||
|
||||
x = x.permute(1, 0, 2) # NLD -> LND
|
||||
x = self.transformer(x)
|
||||
x = x.permute(1, 0, 2) # LND -> NLD
|
||||
|
||||
x = self.ln_post(x[:, 0, :])
|
||||
|
||||
if self.proj is not None:
|
||||
x = x @ self.proj
|
||||
|
||||
return x
|
||||
|
||||
|
||||
class CLIP(nn.Module):
|
||||
def __init__(self,
|
||||
embed_dim: int,
|
||||
# vision
|
||||
image_resolution: int,
|
||||
vision_layers: Union[Tuple[int, int, int, int], int],
|
||||
vision_width: int,
|
||||
vision_patch_size: int,
|
||||
# text
|
||||
context_length: int,
|
||||
vocab_size: int,
|
||||
transformer_width: int,
|
||||
transformer_heads: int,
|
||||
transformer_layers: int
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.context_length = context_length
|
||||
|
||||
if isinstance(vision_layers, (tuple, list)):
|
||||
vision_heads = vision_width * 32 // 64
|
||||
self.visual = ModifiedResNet(
|
||||
layers=vision_layers,
|
||||
output_dim=embed_dim,
|
||||
heads=vision_heads,
|
||||
input_resolution=image_resolution,
|
||||
width=vision_width
|
||||
)
|
||||
else:
|
||||
vision_heads = vision_width // 64
|
||||
self.visual = VisionTransformer(
|
||||
input_resolution=image_resolution,
|
||||
patch_size=vision_patch_size,
|
||||
width=vision_width,
|
||||
layers=vision_layers,
|
||||
heads=vision_heads,
|
||||
output_dim=embed_dim
|
||||
)
|
||||
|
||||
self.transformer = Transformer(
|
||||
width=transformer_width,
|
||||
layers=transformer_layers,
|
||||
heads=transformer_heads,
|
||||
attn_mask=self.build_attention_mask()
|
||||
)
|
||||
|
||||
self.vocab_size = vocab_size
|
||||
self.token_embedding = nn.Embedding(vocab_size, transformer_width)
|
||||
self.positional_embedding = nn.Parameter(torch.empty(self.context_length, transformer_width))
|
||||
self.ln_final = LayerNorm(transformer_width)
|
||||
|
||||
self.text_projection = nn.Parameter(torch.empty(transformer_width, embed_dim))
|
||||
self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07))
|
||||
|
||||
self.initialize_parameters()
|
||||
|
||||
def initialize_parameters(self):
|
||||
nn.init.normal_(self.token_embedding.weight, std=0.02)
|
||||
nn.init.normal_(self.positional_embedding, std=0.01)
|
||||
|
||||
if isinstance(self.visual, ModifiedResNet):
|
||||
if self.visual.attnpool is not None:
|
||||
std = self.visual.attnpool.c_proj.in_features ** -0.5
|
||||
nn.init.normal_(self.visual.attnpool.q_proj.weight, std=std)
|
||||
nn.init.normal_(self.visual.attnpool.k_proj.weight, std=std)
|
||||
nn.init.normal_(self.visual.attnpool.v_proj.weight, std=std)
|
||||
nn.init.normal_(self.visual.attnpool.c_proj.weight, std=std)
|
||||
|
||||
for resnet_block in [self.visual.layer1, self.visual.layer2, self.visual.layer3, self.visual.layer4]:
|
||||
for name, param in resnet_block.named_parameters():
|
||||
if name.endswith("bn3.weight"):
|
||||
nn.init.zeros_(param)
|
||||
|
||||
proj_std = (self.transformer.width ** -0.5) * ((2 * self.transformer.layers) ** -0.5)
|
||||
attn_std = self.transformer.width ** -0.5
|
||||
fc_std = (2 * self.transformer.width) ** -0.5
|
||||
for block in self.transformer.resblocks:
|
||||
nn.init.normal_(block.attn.in_proj_weight, std=attn_std)
|
||||
nn.init.normal_(block.attn.out_proj.weight, std=proj_std)
|
||||
nn.init.normal_(block.mlp.c_fc.weight, std=fc_std)
|
||||
nn.init.normal_(block.mlp.c_proj.weight, std=proj_std)
|
||||
|
||||
if self.text_projection is not None:
|
||||
nn.init.normal_(self.text_projection, std=self.transformer.width ** -0.5)
|
||||
|
||||
def build_attention_mask(self):
|
||||
# lazily create causal attention mask, with full attention between the vision tokens
|
||||
# pytorch uses additive attention mask; fill with -inf
|
||||
mask = torch.empty(self.context_length, self.context_length)
|
||||
mask.fill_(float("-inf"))
|
||||
mask.triu_(1) # zero out the lower diagonal
|
||||
return mask
|
||||
|
||||
@property
|
||||
def dtype(self):
|
||||
return self.visual.conv1.weight.dtype
|
||||
|
||||
def encode_image(self, image):
|
||||
return self.visual(image.type(self.dtype))
|
||||
|
||||
def encode_text(self, text):
|
||||
x = self.token_embedding(text).type(self.dtype) # [batch_size, n_ctx, d_model]
|
||||
|
||||
x = x + self.positional_embedding.type(self.dtype)
|
||||
x = x.permute(1, 0, 2) # NLD -> LND
|
||||
x = self.transformer(x)
|
||||
x = x.permute(1, 0, 2) # LND -> NLD
|
||||
x = self.ln_final(x).type(self.dtype)
|
||||
|
||||
# x.shape = [batch_size, n_ctx, transformer.width]
|
||||
# take features from the eot embedding (eot_token is the highest number in each sequence)
|
||||
x = x[torch.arange(x.shape[0]), text.argmax(dim=-1)] @ self.text_projection
|
||||
|
||||
return x
|
||||
|
||||
def forward(self, image, text):
|
||||
image_features = self.encode_image(image)
|
||||
text_features = self.encode_text(text)
|
||||
|
||||
# normalized features
|
||||
image_features = image_features / image_features.norm(dim=-1, keepdim=True)
|
||||
text_features = text_features / text_features.norm(dim=-1, keepdim=True)
|
||||
|
||||
# cosine similarity as logits
|
||||
logit_scale = self.logit_scale.exp()
|
||||
logits_per_image = logit_scale * image_features @ text_features.t()
|
||||
logits_per_text = logit_scale * text_features @ image_features.t()
|
||||
|
||||
# shape = [global_batch_size, global_batch_size]
|
||||
return logits_per_image, logits_per_text
|
||||
|
||||
|
||||
def convert_weights(model: nn.Module):
|
||||
"""Convert applicable model parameters to fp16"""
|
||||
|
||||
def _convert_weights_to_fp16(l):
|
||||
if isinstance(l, (nn.Conv1d, nn.Conv2d, nn.Linear)):
|
||||
l.weight.data = l.weight.data.half()
|
||||
if l.bias is not None:
|
||||
l.bias.data = l.bias.data.half()
|
||||
|
||||
if isinstance(l, nn.MultiheadAttention):
|
||||
for attr in [*[f"{s}_proj_weight" for s in ["in", "q", "k", "v"]], "in_proj_bias", "bias_k", "bias_v"]:
|
||||
tensor = getattr(l, attr)
|
||||
if tensor is not None:
|
||||
tensor.data = tensor.data.half()
|
||||
|
||||
for name in ["text_projection", "proj"]:
|
||||
if hasattr(l, name):
|
||||
attr = getattr(l, name)
|
||||
if attr is not None:
|
||||
attr.data = attr.data.half()
|
||||
|
||||
model.apply(_convert_weights_to_fp16)
|
||||
|
||||
|
||||
def build_model(state_dict: dict):
|
||||
vit = "visual.proj" in state_dict
|
||||
|
||||
if vit:
|
||||
vision_width = state_dict["visual.conv1.weight"].shape[0]
|
||||
vision_layers = len(
|
||||
[k for k in state_dict.keys() if k.startswith("visual.") and k.endswith(".attn.in_proj_weight")])
|
||||
vision_patch_size = state_dict["visual.conv1.weight"].shape[-1]
|
||||
grid_size = round((state_dict["visual.positional_embedding"].shape[0] - 1) ** 0.5)
|
||||
image_resolution = vision_patch_size * grid_size
|
||||
else:
|
||||
counts: list = [len(set(k.split(".")[2] for k in state_dict if k.startswith(f"visual.layer{b}"))) for b in
|
||||
[1, 2, 3, 4]]
|
||||
vision_layers = tuple(counts)
|
||||
vision_width = state_dict["visual.layer1.0.conv1.weight"].shape[0]
|
||||
output_width = round((state_dict["visual.attnpool.positional_embedding"].shape[0] - 1) ** 0.5)
|
||||
vision_patch_size = None
|
||||
assert output_width ** 2 + 1 == state_dict["visual.attnpool.positional_embedding"].shape[0]
|
||||
image_resolution = output_width * 32
|
||||
|
||||
embed_dim = state_dict["text_projection"].shape[1]
|
||||
context_length = state_dict["positional_embedding"].shape[0]
|
||||
vocab_size = state_dict["token_embedding.weight"].shape[0]
|
||||
transformer_width = state_dict["ln_final.weight"].shape[0]
|
||||
transformer_heads = transformer_width // 64
|
||||
transformer_layers = len(set(k.split(".")[2] for k in state_dict if k.startswith(f"transformer.resblocks")))
|
||||
|
||||
model = CLIP(
|
||||
embed_dim,
|
||||
image_resolution, vision_layers, vision_width, vision_patch_size,
|
||||
context_length, vocab_size, transformer_width, transformer_heads, transformer_layers
|
||||
)
|
||||
|
||||
for key in ["input_resolution", "context_length", "vocab_size"]:
|
||||
if key in state_dict:
|
||||
del state_dict[key]
|
||||
|
||||
convert_weights(model)
|
||||
model.load_state_dict(state_dict)
|
||||
return model.eval()
|
||||
134
clip/simple_tokenizer.py
Normal file
@@ -0,0 +1,134 @@
|
||||
import gzip
|
||||
import html
|
||||
import os
|
||||
from functools import lru_cache
|
||||
|
||||
import ftfy
|
||||
import regex as re
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def default_bpe():
|
||||
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "bpe_simple_vocab_16e6.txt.gz")
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def bytes_to_unicode():
|
||||
"""
|
||||
Returns list of utf-8 byte and a corresponding list of unicode strings.
|
||||
The reversible bpe codes work on unicode strings.
|
||||
This means you need a large # of unicode characters in your vocab if you want to avoid UNKs.
|
||||
When you're at something like a 10B token dataset you end up needing around 5K for decent coverage.
|
||||
This is a signficant percentage of your normal, say, 32K bpe vocab.
|
||||
To avoid that, we want lookup tables between utf-8 bytes and unicode strings.
|
||||
And avoids mapping to whitespace/control characters the bpe code barfs on.
|
||||
"""
|
||||
bs = list(range(ord("!"), ord("~") + 1)) + list(range(ord("¡"), ord("¬") + 1)) + list(range(ord("®"), ord("ÿ") + 1))
|
||||
cs = bs[:]
|
||||
n = 0
|
||||
for b in range(2 ** 8):
|
||||
if b not in bs:
|
||||
bs.append(b)
|
||||
cs.append(2 ** 8 + n)
|
||||
n += 1
|
||||
cs = [chr(n) for n in cs]
|
||||
return dict(zip(bs, cs))
|
||||
|
||||
|
||||
def get_pairs(word):
|
||||
"""Return set of symbol pairs in a word.
|
||||
Word is represented as tuple of symbols (symbols being variable-length strings).
|
||||
"""
|
||||
pairs = set()
|
||||
prev_char = word[0]
|
||||
for char in word[1:]:
|
||||
pairs.add((prev_char, char))
|
||||
prev_char = char
|
||||
return pairs
|
||||
|
||||
|
||||
def basic_clean(text):
|
||||
text = ftfy.fix_text(text)
|
||||
text = html.unescape(html.unescape(text))
|
||||
return text.strip()
|
||||
|
||||
|
||||
def whitespace_clean(text):
|
||||
text = re.sub(r'\s+', ' ', text)
|
||||
text = text.strip()
|
||||
return text
|
||||
|
||||
|
||||
class SimpleTokenizer(object):
|
||||
def __init__(self, bpe_path: str = default_bpe()):
|
||||
self.byte_encoder = bytes_to_unicode()
|
||||
self.byte_decoder = {v: k for k, v in self.byte_encoder.items()}
|
||||
merges = gzip.open(bpe_path).read().decode("utf-8").split('\n')
|
||||
merges = merges[1:49152 - 256 - 2 + 1]
|
||||
merges = [tuple(merge.split()) for merge in merges]
|
||||
vocab = list(bytes_to_unicode().values())
|
||||
vocab = vocab + [v + '</w>' for v in vocab]
|
||||
for merge in merges:
|
||||
vocab.append(''.join(merge))
|
||||
vocab.extend(['<|startoftext|>', '<|endoftext|>'])
|
||||
self.encoder = dict(zip(vocab, range(len(vocab))))
|
||||
self.decoder = {v: k for k, v in self.encoder.items()}
|
||||
self.bpe_ranks = dict(zip(merges, range(len(merges))))
|
||||
self.cache = {'<|startoftext|>': '<|startoftext|>', '<|endoftext|>': '<|endoftext|>'}
|
||||
self.pat = re.compile(
|
||||
r"""<\|startoftext\|>|<\|endoftext\|>|'s|'t|'re|'ve|'m|'ll|'d|[\p{L}]+|[\p{N}]|[^\s\p{L}\p{N}]+""",
|
||||
re.IGNORECASE)
|
||||
|
||||
def bpe(self, token):
|
||||
if token in self.cache:
|
||||
return self.cache[token]
|
||||
word = tuple(token[:-1]) + (token[-1] + '</w>',)
|
||||
pairs = get_pairs(word)
|
||||
|
||||
if not pairs:
|
||||
return token + '</w>'
|
||||
|
||||
while True:
|
||||
bigram = min(pairs, key=lambda pair: self.bpe_ranks.get(pair, float('inf')))
|
||||
if bigram not in self.bpe_ranks:
|
||||
break
|
||||
first, second = bigram
|
||||
new_word = []
|
||||
i = 0
|
||||
while i < len(word):
|
||||
try:
|
||||
j = word.index(first, i)
|
||||
new_word.extend(word[i:j])
|
||||
i = j
|
||||
except:
|
||||
new_word.extend(word[i:])
|
||||
break
|
||||
|
||||
if word[i] == first and i < len(word) - 1 and word[i + 1] == second:
|
||||
new_word.append(first + second)
|
||||
i += 2
|
||||
else:
|
||||
new_word.append(word[i])
|
||||
i += 1
|
||||
new_word = tuple(new_word)
|
||||
word = new_word
|
||||
if len(word) == 1:
|
||||
break
|
||||
else:
|
||||
pairs = get_pairs(word)
|
||||
word = ' '.join(word)
|
||||
self.cache[token] = word
|
||||
return word
|
||||
|
||||
def encode(self, text):
|
||||
bpe_tokens = []
|
||||
text = whitespace_clean(basic_clean(text)).lower()
|
||||
for token in re.findall(self.pat, text):
|
||||
token = ''.join(self.byte_encoder[b] for b in token.encode('utf-8'))
|
||||
bpe_tokens.extend(self.encoder[bpe_token] for bpe_token in self.bpe(token).split(' '))
|
||||
return bpe_tokens
|
||||
|
||||
def decode(self, tokens):
|
||||
text = ''.join([self.decoder[token] for token in tokens])
|
||||
text = bytearray([self.byte_decoder[c] for c in text]).decode('utf-8', errors="replace").replace('</w>', ' ')
|
||||
return text
|
||||
605
clip_make_pic.py
Normal file
@@ -0,0 +1,605 @@
|
||||
import matplotlib
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
# matplotlib画图中中文显示会有问题,需要这两行设置默认字体.没中文可以去掉
|
||||
plt.rcParams['font.sans-serif']=['SimHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
|
||||
# 设置figure_size尺寸
|
||||
# plt.rcParams['figure.figsize'] = (22.0, 22.0)
|
||||
plt.rcParams['figure.figsize'] = (5.0,5.0)
|
||||
fig = plt.figure()
|
||||
|
||||
# 设定图表颜色
|
||||
fig.set(alpha=0.2)
|
||||
#fig.suptitle('suptitle', fontsize=24, x=0.6,y=0.9, horizontalalignment='left', va='bottom')
|
||||
|
||||
# 输入数据
|
||||
# plt.subplot2grid((4,3),(0,0))
|
||||
#Average over 11 datasets
|
||||
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
|
||||
# CR_CLIP=[65.67090909,68.98363636,72.51636364,75.58,78.20090909]
|
||||
#
|
||||
# GPT_CLIP=[65.54,68.59,72.23,75.31,77.94]
|
||||
#
|
||||
# DA_CLIP=[65.27,68.20,72.01,75.21,77.70]
|
||||
#
|
||||
#
|
||||
# y_tip_adapter=[62.3282,64.6182,66.5327,68.4955,70.3182]
|
||||
#
|
||||
# y_tip_adapter_f=[63.2982,65.93913,68.9836,72.1573,75.1346]
|
||||
#
|
||||
# y_clip_adapter=[62.6745,65.5527,68.6055,71.3964,74.4436]
|
||||
#
|
||||
# y_imagenet_CoOp=[59.5882,62.3236,66.7664,69.8918,73.4251]
|
||||
# y_clip=[58.9627]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
# #
|
||||
# # #数据及线属性
|
||||
# # #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('Average over 11 datasets',fontproperties='Times New Roman', fontsize=15,fontweight='bold')
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("Average.png", dpi=600)
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
#
|
||||
#
|
||||
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(0,1))
|
||||
|
||||
# CR_CLIP=[90.3,90.82,92.45,92.77,94.22]
|
||||
# GPT_CLIP=[89.73,90.54,92.26,92.57,93.96]
|
||||
# DA_CLIP=[89.45,90.34,91.89,92.09,93.79]
|
||||
#
|
||||
# y_tip_adapter=[87.18,88.44,89.39,89.83,90.18]
|
||||
# y_tip_adapter_f=[87.9,89.4,90.78,91.1,92.28]
|
||||
# y_imagenet_CoOp=[87.53,87.93,89.55,90.21,91.83]
|
||||
# y_clip_adapter=[88.6,89.37,89.98,91.4,92.49]
|
||||
#
|
||||
# y_clip=[86.29]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('Caltech101',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("Caltech101.png", dpi=600)
|
||||
#
|
||||
#
|
||||
# #
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(0,2))
|
||||
# #
|
||||
# CR_CLIP=[50.73,56.51,62.2,66.76,69.71]
|
||||
#
|
||||
# GPT_CLIP=[50.52,56.21,61.92,66.58,69.31]
|
||||
#
|
||||
# DA_CLIP=[46.28,52.19,61.76,66.19,68.79]
|
||||
#
|
||||
# y_tip_adapter=[46.22,49.47,53.96,58.63,60.93]
|
||||
#
|
||||
# y_tip_adapter_f=[48.58,51.64,57.21,61.92,66.23]
|
||||
#
|
||||
# y_imagenet_CoOp=[44.39,45.15,53.49,59.97,63.58]
|
||||
#
|
||||
# y_clip_adapter=[45.8,51.48,56.86,61,65.96]
|
||||
#
|
||||
# y_clip=[42.32]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('DTD',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("DTD.png", dpi=600)
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# # 输入数据
|
||||
# # plt.subplot2grid((4,3),(1,0))
|
||||
# # #EuroSAT
|
||||
# CR_CLIP=[58.85,67.38,78.54,84.84,84.90]
|
||||
#
|
||||
# GPT_CLIP=[58.46,66.96,78.34,84.24,84.44]
|
||||
#
|
||||
# DA_CLIP=[57.41,66.41,77.95,83.90,84.17]
|
||||
#
|
||||
# y_tip_adapter=[54.38,61.68,65.32,67.95,70.54]
|
||||
#
|
||||
# y_tip_adapter_f=[51.81,66.32,69.23,77.69,81.96]
|
||||
#
|
||||
# y_clip_adapter=[61.4,63.9,73.38,77.93,84.43]
|
||||
#
|
||||
# y_imagenet_CoOp=[50.63,61.5,70.18,76.73,83.53]
|
||||
#
|
||||
# y_clip=[37.56]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('EuroSAT',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("EuroSAT.png", dpi=600)
|
||||
#
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(1,1))
|
||||
# #FGVCAircraft
|
||||
# CR_CLIP=[22.92,24.82,28.68,34.88,42.66]
|
||||
#
|
||||
# GPT_CLIP=[22.70,24.62,28.18,34.59,42.30]
|
||||
#
|
||||
# DA_CLIP=[22.53,24.48,28.08,34.26,41.34]
|
||||
#
|
||||
# y_tip_adapter=[19.05,21.2,22.41,25.59,29.76]
|
||||
#
|
||||
# y_tip_adapter_f=[20.06,21.17,24.97,28.13,34.83]
|
||||
#
|
||||
# y_imagenet_CoOp=[9.64,18.68,21.87,26.13,31.26]
|
||||
#
|
||||
# y_clip_adapter=[17.49,20.1,22.59,26.25,32.1]
|
||||
#
|
||||
# y_clip=[17.28]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('FGVCAircraft',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("FGVCAircraft.png", dpi=600)
|
||||
# #
|
||||
# #
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(1,2))
|
||||
# #Flowers102
|
||||
# CR_CLIP=[80.88,88.8,93.68,96.20,96.7]
|
||||
#
|
||||
# GPT_CLIP=[80.76,87.80,93.32,95.67,96.66]
|
||||
#
|
||||
# DA_CLIP=[80.88,87.78,93.26,95.82,96.80]
|
||||
#
|
||||
# y_tip_adapter=[73.12,79.13,83.8,87.98,89.89]
|
||||
#
|
||||
# y_tip_adapter_f=[76.7,79.5,89,92.4,93.9]
|
||||
#
|
||||
# y_imagenet_CoOp=[68.12,77.51,86.2,91.18,94.51]
|
||||
#
|
||||
# y_clip_adapter=[73.49,81.61,87.17,91.72,93.9]
|
||||
#
|
||||
# y_clip=[66.14]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('Flowers102',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("Flowers102.png", dpi=600)
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(2,0))
|
||||
#Food101
|
||||
# CR_CLIP=[78.44,78.67,78.81,78.96,79.72]
|
||||
#
|
||||
# GPT_CLIP=[78.24,78.56,78.67,78.82,79.59]
|
||||
#
|
||||
# DA_CLIP=[78.17,78.34,78.50,78.55,79.40]
|
||||
#
|
||||
# y_tip_adapter=[77.42,77.52,77.54,77.76,77.83]
|
||||
#
|
||||
# y_tip_adapter_f=[77.27,77.44,77.2,78.36,79.05]
|
||||
#
|
||||
# y_imagenet_CoOp=[74.32,72.49,73.33,71.82,74.67]
|
||||
#
|
||||
# y_clip_adapter=[76.82,77.22,77.92,78.04,78.25]
|
||||
#
|
||||
# y_clip=[77.31]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('Food101',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("Food101.png", dpi=600)
|
||||
# #
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(2,1))
|
||||
# #imagenet
|
||||
# CR_CLIP=[62,63.14,63.52,65.02,66.46]
|
||||
# GPT_CLIP=[61.82,62.83,63.27,64.72,66.25]
|
||||
# DA_CLIP=[61.41,61.83,62.91,64.54,66.09]
|
||||
#
|
||||
# y_tip_adapter=[60.7,60.96,60.98,61.45,62.03]
|
||||
# y_tip_adapter_f=[61.32,61.69,62.52,64,65.51]
|
||||
# y_clip_adapter=[61.2,61.52,61.84,62.68,63.59]
|
||||
# y_imagenet_CoOp=[57.15,57.81,59.99,61.56,62.95]
|
||||
# y_clip=[60.33]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('ImageNet',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# #plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
#
|
||||
# plt.savefig("ImageNet.png", dpi=600)
|
||||
#
|
||||
#
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(2,2))
|
||||
# #OxfordPets
|
||||
# CR_CLIP=[86.1,87.94,88.74,89.25,90.13]
|
||||
#
|
||||
# GPT_CLIP=[85.94,86.79,88.63,89.01,89.92]
|
||||
#
|
||||
# DA_CLIP=[85.91,86.75,88.50,88.96,89.86]
|
||||
#
|
||||
# y_tip_adapter=[86.1,87.03,86.45,87.03,88.14]
|
||||
#
|
||||
# y_tip_adapter_f=[86.44,86.44,87,88.11,89.13]
|
||||
# y_imagenet_CoOp=[85.89,82.64,86.7,85.32,87.01]
|
||||
# y_clip_adapter=[85.99,86.73,87.46,87.65,87.84]
|
||||
# y_clip=[85.77]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('OxfordPets',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
#
|
||||
# plt.savefig("OxfordPets.png", dpi=600)
|
||||
|
||||
|
||||
|
||||
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(3,0))
|
||||
# #StanfordCars
|
||||
# CR_CLIP=[60.17,62.57,66.92,73.92,78]
|
||||
#
|
||||
# GPT_CLIP=[60.13,62.46,66.73,73.81,79.72]
|
||||
#
|
||||
# DA_CLIP=[59.77,62.12,66.30,73.35,79.54]
|
||||
#
|
||||
# y_tip_adapter=[57.54,57.93,61.45,62.93,66.77]
|
||||
#
|
||||
# y_tip_adapter_f=[58.42,61.06,64.54,69.32,75.08]
|
||||
#
|
||||
# y_imagenet_CoOp=[55.59,58.28,62.62,68.43,73.3659]
|
||||
#
|
||||
# y_clip_adapter=[55.13,58.74,62.45,67.89,74.01]
|
||||
#
|
||||
# y_clip=[55.61]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('StanfordCars',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# #plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("StanfordCars.png", dpi=600)
|
||||
|
||||
|
||||
|
||||
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(3,1))
|
||||
# #SUN397
|
||||
# CR_CLIP=[64.1,66.34,69.24,70.78,73.21]
|
||||
#
|
||||
# GPT_CLIP=[63.91,66.23,68.52,70.59,72.98]
|
||||
#
|
||||
# DA_CLIP=[63.42,65.24,68.13,70.10,72.69]
|
||||
#
|
||||
# y_tip_adapter=[61.3,62.7,64.1,65.62,66.85]
|
||||
#
|
||||
# y_tip_adapter_f=[62.4,63.22,65.75,68.28,71.27]
|
||||
# y_imagenet_CoOp=[60.29,59.48,63.47,65.52,69.26]
|
||||
#
|
||||
# y_clip_adapter=[61.3,63.29,65.96,67.5,69.55]
|
||||
#
|
||||
# y_clip=[58.52]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('SUN397',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("SUN397.png", dpi=600)
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(3,2))
|
||||
# #UCF101
|
||||
CR_CLIP=[67.86,71.73,75,78.2,82.5]
|
||||
|
||||
GPT_CLIP=[67.60,71.46,74.72,77.86,82.26]
|
||||
|
||||
DA_CLIP=[67.46,71.27,74.49,77.77,82.08]
|
||||
|
||||
y_tip_adapter=[62.6,64.74,66.46,68.68,70.58]
|
||||
|
||||
y_tip_adapter_f=[65.38,67.45,71.17,74.42,77.24]
|
||||
|
||||
y_imagenet_CoOp=[61.92,64.09,67.03,71.94,75.71]
|
||||
|
||||
y_clip_adapter=[62.2,67.12,69.05,73.3,76.76]
|
||||
|
||||
y_clip=[61.46]
|
||||
x=[1,2,4,8,16]
|
||||
x_zero=[0]
|
||||
|
||||
# 数据及线属性
|
||||
# cacfc
|
||||
plt.plot(x, CR_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='CR-CLIP')
|
||||
plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
#clip_adapter
|
||||
|
||||
plt.grid(linestyle="--")
|
||||
# 修改坐标轴字体及大小
|
||||
plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
#标题设置
|
||||
plt.title('UCF101',fontproperties='Times New Roman', fontsize=15)
|
||||
plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# 添加标签
|
||||
plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
|
||||
plt.savefig("UCF101.png", dpi=600)
|
||||
# plt.show()
|
||||
77
daln/grl.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from typing import Optional, Any, Tuple
|
||||
import numpy as np
|
||||
import torch.nn as nn
|
||||
from torch.autograd import Function
|
||||
import torch
|
||||
|
||||
|
||||
class GradientReverseFunction(Function):
|
||||
|
||||
@staticmethod
|
||||
def forward(ctx: Any, input: torch.Tensor, coeff: Optional[float] = 1.) -> torch.Tensor:
|
||||
ctx.coeff = coeff
|
||||
output = input * 1.0
|
||||
return output
|
||||
|
||||
@staticmethod
|
||||
def backward(ctx: Any, grad_output: torch.Tensor) -> Tuple[torch.Tensor, Any]:
|
||||
return grad_output.neg() * ctx.coeff, None
|
||||
|
||||
|
||||
class GradientReverseLayer(nn.Module):
|
||||
def __init__(self):
|
||||
super(GradientReverseLayer, self).__init__()
|
||||
|
||||
def forward(self, *input):
|
||||
return GradientReverseFunction.apply(*input)
|
||||
|
||||
|
||||
class WarmStartGradientReverseLayer(nn.Module):
|
||||
"""Gradient Reverse Layer :math:`\mathcal{R}(x)` with warm start
|
||||
|
||||
The forward and backward behaviours are:
|
||||
|
||||
.. math::
|
||||
\mathcal{R}(x) = x,
|
||||
|
||||
\dfrac{ d\mathcal{R}} {dx} = - \lambda I.
|
||||
|
||||
:math:`\lambda` is initiated at :math:`lo` and is gradually changed to :math:`hi` using the following schedule:
|
||||
|
||||
.. math::
|
||||
\lambda = \dfrac{2(hi-lo)}{1+\exp(- α \dfrac{i}{N})} - (hi-lo) + lo
|
||||
|
||||
where :math:`i` is the iteration step.
|
||||
|
||||
Args:
|
||||
alpha (float, optional): :math:`α`. Default: 1.0
|
||||
lo (float, optional): Initial value of :math:`\lambda`. Default: 0.0
|
||||
hi (float, optional): Final value of :math:`\lambda`. Default: 1.0
|
||||
max_iters (int, optional): :math:`N`. Default: 1000
|
||||
auto_step (bool, optional): If True, increase :math:`i` each time `forward` is called.
|
||||
Otherwise use function `step` to increase :math:`i`. Default: False
|
||||
"""
|
||||
|
||||
def __init__(self, alpha: Optional[float] = 1.0, lo: Optional[float] = 0.0, hi: Optional[float] = 1.,
|
||||
max_iters: Optional[int] = 1000., auto_step: Optional[bool] = False):
|
||||
super(WarmStartGradientReverseLayer, self).__init__()
|
||||
self.alpha = alpha
|
||||
self.lo = lo
|
||||
self.hi = hi
|
||||
self.iter_num = 0
|
||||
self.max_iters = max_iters
|
||||
self.auto_step = auto_step
|
||||
|
||||
def forward(self, input: torch.Tensor) -> torch.Tensor:
|
||||
""""""
|
||||
coeff =float(
|
||||
2.0 * (self.hi - self.lo) / (1.0 + np.exp(-self.alpha * self.iter_num / self.max_iters))
|
||||
- (self.hi - self.lo) + self.lo
|
||||
)
|
||||
if self.auto_step:
|
||||
self.step()
|
||||
return GradientReverseFunction.apply(input, coeff)
|
||||
|
||||
def step(self):
|
||||
"""Increase iteration number :math:`i` by 1"""
|
||||
self.iter_num += 1
|
||||
25
daln/nwd.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as F
|
||||
from daln.grl import WarmStartGradientReverseLayer
|
||||
|
||||
|
||||
class NuclearWassersteinDiscrepancy(nn.Module):
|
||||
def __init__(self, classifier: nn.Module):
|
||||
super(NuclearWassersteinDiscrepancy, self).__init__()
|
||||
self.grl = WarmStartGradientReverseLayer(alpha=1., lo=0., hi=1., max_iters=1000, auto_step=True)
|
||||
self.classifier = classifier
|
||||
|
||||
@staticmethod
|
||||
def n_discrepancy(y_s: torch.Tensor, y_t: torch.Tensor) -> torch.Tensor:
|
||||
pre_s, pre_t = F.softmax(y_s, dim=1), F.softmax(y_t, dim=1)
|
||||
loss = (-torch.norm(pre_t, 'nuc') + torch.norm(pre_s, 'nuc')) / y_t.shape[0]
|
||||
return loss
|
||||
|
||||
def forward(self, f: torch.Tensor) -> torch.Tensor:
|
||||
f_grl = self.grl(f)
|
||||
y = self.classifier(f_grl)
|
||||
y_s, y_t = y.chunk(2, dim=0)
|
||||
|
||||
loss = self.n_discrepancy(y_s, y_t)
|
||||
return loss
|
||||
0
data/__init__.py
Normal file
140
data/folder_new.py
Normal file
@@ -0,0 +1,140 @@
|
||||
### Modify the ImageFolder function to get the image path in the data loader
|
||||
import torch.utils.data as data
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
import os.path
|
||||
from PIL import ImageFile
|
||||
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True ## used to handle some error when loading the special images.
|
||||
|
||||
print('the data loader file has been modified')
|
||||
IMG_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm']
|
||||
|
||||
|
||||
def is_image_file(filename):
|
||||
"""Checks if a file is an image.
|
||||
Args:
|
||||
filename (string): path to a file
|
||||
Returns:
|
||||
bool: True if the filename ends with a known image extension
|
||||
"""
|
||||
filename_lower = filename.lower()
|
||||
return any(filename_lower.endswith(ext) for ext in IMG_EXTENSIONS)
|
||||
|
||||
|
||||
def find_classes(dir):
|
||||
classes = [d for d in os.listdir(dir) if os.path.isdir(os.path.join(dir, d))]
|
||||
classes.sort()
|
||||
class_to_idx = {classes[i]: i for i in range(len(classes))}
|
||||
return classes, class_to_idx
|
||||
|
||||
|
||||
def make_dataset(dir, class_to_idx):
|
||||
images = []
|
||||
dir = os.path.expanduser(dir)
|
||||
for target in sorted(os.listdir(dir)):
|
||||
d = os.path.join(dir, target)
|
||||
if not os.path.isdir(d):
|
||||
continue
|
||||
|
||||
for root, _, fnames in sorted(os.walk(d)): # os.walk()是一种遍历目录数的函数
|
||||
for fname in sorted(fnames):
|
||||
if is_image_file(fname):
|
||||
path = os.path.join(root, fname)
|
||||
item = (path, class_to_idx[target])
|
||||
images.append(item)
|
||||
|
||||
return images
|
||||
|
||||
|
||||
def pil_loader(path):
|
||||
# open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
|
||||
with open(path, 'rb') as f:
|
||||
img = Image.open(f)
|
||||
return img.convert('RGB')
|
||||
|
||||
|
||||
def accimage_loader(path):
|
||||
import accimage
|
||||
try:
|
||||
return accimage.Image(path)
|
||||
except IOError:
|
||||
# Potentially a decoding problem, fall back to PIL.Image
|
||||
return pil_loader(path)
|
||||
|
||||
|
||||
def default_loader(path):
|
||||
from torchvision import get_image_backend
|
||||
if get_image_backend() == 'accimage':
|
||||
return accimage_loader(path)
|
||||
else:
|
||||
return pil_loader(path)
|
||||
|
||||
|
||||
class ImageFolder_new(data.Dataset):
|
||||
"""A generic data loader where the images are arranged in this way: ::
|
||||
root/dog/xxx.png
|
||||
root/dog/xxy.png
|
||||
root/dog/xxz.png
|
||||
root/cat/123.png
|
||||
root/cat/nsdf3.png
|
||||
root/cat/asd932_.png
|
||||
Args:
|
||||
root (string): Root directory path.
|
||||
transform (callable, optional): A function/transform that takes in an PIL image
|
||||
and returns a transformed version. E.g, ``transforms.RandomCrop``
|
||||
target_transform (callable, optional): A function/transform that takes in the
|
||||
target and transforms it.
|
||||
loader (callable, optional): A function to load an image given its path.
|
||||
Attributes:
|
||||
classes (list): List of the class names.
|
||||
class_to_idx (dict): Dict with items (class_name, class_index).
|
||||
imgs (list): List of (image path, class_index) tuples
|
||||
"""
|
||||
|
||||
def __init__(self, root, transform=None, target_transform=None,
|
||||
loader=default_loader):
|
||||
classes, class_to_idx = find_classes(root)
|
||||
imgs = make_dataset(root, class_to_idx)
|
||||
if len(imgs) == 0:
|
||||
raise (RuntimeError("Found 0 images in subfolders of: " + root + "\n"
|
||||
"Supported image extensions are: " + ",".join(
|
||||
IMG_EXTENSIONS)))
|
||||
|
||||
self.root = root
|
||||
self.imgs = imgs
|
||||
self.classes = classes
|
||||
self.class_to_idx = class_to_idx
|
||||
self.transform = transform
|
||||
self.target_transform = target_transform
|
||||
self.loader = loader
|
||||
|
||||
def __getitem__(self, index):
|
||||
"""
|
||||
Args:
|
||||
index (int): Index
|
||||
Returns:
|
||||
tuple: (image, target) where target is class_index of the target class.
|
||||
"""
|
||||
path, target = self.imgs[index]
|
||||
img = self.loader(path)
|
||||
if self.transform is not None:
|
||||
img = self.transform(img)
|
||||
if self.target_transform is not None:
|
||||
target = self.target_transform(target)
|
||||
|
||||
return img, target, path
|
||||
|
||||
def __len__(self):
|
||||
return len(self.imgs)
|
||||
|
||||
def __repr__(self):
|
||||
fmt_str = 'Dataset ' + self.__class__.__name__ + '\n'
|
||||
fmt_str += ' Number of datapoints: {}\n'.format(self.__len__())
|
||||
fmt_str += ' Root Location: {}\n'.format(self.root)
|
||||
tmp = ' Transforms (if any): '
|
||||
fmt_str += '{0}{1}\n'.format(tmp, self.transform.__repr__().replace('\n', '\n' + ' ' * len(tmp)))
|
||||
tmp = ' Target Transforms (if any): '
|
||||
fmt_str += '{0}{1}'.format(tmp, self.target_transform.__repr__().replace('\n', '\n' + ' ' * len(tmp)))
|
||||
return fmt_str
|
||||
233
data/prepare_data.py
Normal file
@@ -0,0 +1,233 @@
|
||||
import os
|
||||
import torch
|
||||
import torchvision.transforms as transforms
|
||||
import torchvision.datasets as datasets
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from collections import defaultdict
|
||||
import random
|
||||
|
||||
|
||||
def generate_dataloader(args, preprocess):
|
||||
templates = [
|
||||
"itap of a {}.",
|
||||
"a bad photo of the {}.",
|
||||
"a origami {}.",
|
||||
"a photo of the large {}.",
|
||||
"a {} in a video game.",
|
||||
"art of the {}.",
|
||||
"a photo of the small {}.",
|
||||
]
|
||||
imagenet_classes = ["tench", "goldfish", "great white shark", "tiger shark", "hammerhead shark", "electric ray",
|
||||
"stingray", "rooster", "hen", "ostrich", "brambling", "goldfinch", "house finch", "junco",
|
||||
"indigo bunting", "American robin", "bulbul", "jay", "magpie", "chickadee", "American dipper",
|
||||
"kite (bird of prey)", "bald eagle", "vulture", "great grey owl", "fire salamander",
|
||||
"smooth newt", "newt", "spotted salamander", "axolotl", "American bullfrog", "tree frog",
|
||||
"tailed frog", "loggerhead sea turtle", "leatherback sea turtle", "mud turtle", "terrapin",
|
||||
"box turtle", "banded gecko", "green iguana", "Carolina anole",
|
||||
"desert grassland whiptail lizard", "agama", "frilled-necked lizard", "alligator lizard",
|
||||
"Gila monster", "European green lizard", "chameleon", "Komodo dragon", "Nile crocodile",
|
||||
"American alligator", "triceratops", "worm snake", "ring-necked snake",
|
||||
"eastern hog-nosed snake", "smooth green snake", "kingsnake", "garter snake", "water snake",
|
||||
"vine snake", "night snake", "boa constrictor", "African rock python", "Indian cobra",
|
||||
"green mamba", "sea snake", "Saharan horned viper", "eastern diamondback rattlesnake",
|
||||
"sidewinder rattlesnake", "trilobite", "harvestman", "scorpion", "yellow garden spider",
|
||||
"barn spider", "European garden spider", "southern black widow", "tarantula", "wolf spider",
|
||||
"tick", "centipede", "black grouse", "ptarmigan", "ruffed grouse", "prairie grouse", "peafowl",
|
||||
"quail", "partridge", "african grey parrot", "macaw", "sulphur-crested cockatoo", "lorikeet",
|
||||
"coucal", "bee eater", "hornbill", "hummingbird", "jacamar", "toucan", "duck",
|
||||
"red-breasted merganser", "goose", "black swan", "tusker", "echidna", "platypus", "wallaby",
|
||||
"koala", "wombat", "jellyfish", "sea anemone", "brain coral", "flatworm", "nematode", "conch",
|
||||
"snail", "slug", "sea slug", "chiton", "chambered nautilus", "Dungeness crab", "rock crab",
|
||||
"fiddler crab", "red king crab", "American lobster", "spiny lobster", "crayfish", "hermit crab",
|
||||
"isopod", "white stork", "black stork", "spoonbill", "flamingo", "little blue heron",
|
||||
"great egret", "bittern bird", "crane bird", "limpkin", "common gallinule", "American coot",
|
||||
"bustard", "ruddy turnstone", "dunlin", "common redshank", "dowitcher", "oystercatcher",
|
||||
"pelican", "king penguin", "albatross", "grey whale", "killer whale", "dugong", "sea lion",
|
||||
"Chihuahua", "Japanese Chin", "Maltese", "Pekingese", "Shih Tzu", "King Charles Spaniel",
|
||||
"Papillon", "toy terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset Hound", "Beagle",
|
||||
"Bloodhound", "Bluetick Coonhound", "Black and Tan Coonhound", "Treeing Walker Coonhound",
|
||||
"English foxhound", "Redbone Coonhound", "borzoi", "Irish Wolfhound", "Italian Greyhound",
|
||||
"Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound",
|
||||
"Weimaraner", "Staffordshire Bull Terrier", "American Staffordshire Terrier",
|
||||
"Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier",
|
||||
"Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire Fox Terrier",
|
||||
"Lakeland Terrier", "Sealyham Terrier", "Airedale Terrier", "Cairn Terrier",
|
||||
"Australian Terrier", "Dandie Dinmont Terrier", "Boston Terrier", "Miniature Schnauzer",
|
||||
"Giant Schnauzer", "Standard Schnauzer", "Scottish Terrier", "Tibetan Terrier",
|
||||
"Australian Silky Terrier", "Soft-coated Wheaten Terrier", "West Highland White Terrier",
|
||||
"Lhasa Apso", "Flat-Coated Retriever", "Curly-coated Retriever", "Golden Retriever",
|
||||
"Labrador Retriever", "Chesapeake Bay Retriever", "German Shorthaired Pointer", "Vizsla",
|
||||
"English Setter", "Irish Setter", "Gordon Setter", "Brittany dog", "Clumber Spaniel",
|
||||
"English Springer Spaniel", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel",
|
||||
"Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael dog", "Malinois", "Briard",
|
||||
"Australian Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "collie",
|
||||
"Border Collie", "Bouvier des Flandres dog", "Rottweiler", "German Shepherd Dog", "Dobermann",
|
||||
"Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog",
|
||||
"Appenzeller Sennenhund", "Entlebucher Sennenhund", "Boxer", "Bullmastiff", "Tibetan Mastiff",
|
||||
"French Bulldog", "Great Dane", "St. Bernard", "husky", "Alaskan Malamute", "Siberian Husky",
|
||||
"Dalmatian", "Affenpinscher", "Basenji", "pug", "Leonberger", "Newfoundland dog",
|
||||
"Great Pyrenees dog", "Samoyed", "Pomeranian", "Chow Chow", "Keeshond", "brussels griffon",
|
||||
"Pembroke Welsh Corgi", "Cardigan Welsh Corgi", "Toy Poodle", "Miniature Poodle",
|
||||
"Standard Poodle", "Mexican hairless dog (xoloitzcuintli)", "grey wolf", "Alaskan tundra wolf",
|
||||
"red wolf or maned wolf", "coyote", "dingo", "dhole", "African wild dog", "hyena", "red fox",
|
||||
"kit fox", "Arctic fox", "grey fox", "tabby cat", "tiger cat", "Persian cat", "Siamese cat",
|
||||
"Egyptian Mau", "cougar", "lynx", "leopard", "snow leopard", "jaguar", "lion", "tiger",
|
||||
"cheetah", "brown bear", "American black bear", "polar bear", "sloth bear", "mongoose",
|
||||
"meerkat", "tiger beetle", "ladybug", "ground beetle", "longhorn beetle", "leaf beetle",
|
||||
"dung beetle", "rhinoceros beetle", "weevil", "fly", "bee", "ant", "grasshopper",
|
||||
"cricket insect", "stick insect", "cockroach", "praying mantis", "cicada", "leafhopper",
|
||||
"lacewing", "dragonfly", "damselfly", "red admiral butterfly", "ringlet butterfly",
|
||||
"monarch butterfly", "small white butterfly", "sulphur butterfly", "gossamer-winged butterfly",
|
||||
"starfish", "sea urchin", "sea cucumber", "cottontail rabbit", "hare", "Angora rabbit",
|
||||
"hamster", "porcupine", "fox squirrel", "marmot", "beaver", "guinea pig", "common sorrel horse",
|
||||
"zebra", "pig", "wild boar", "warthog", "hippopotamus", "ox", "water buffalo", "bison",
|
||||
"ram (adult male sheep)", "bighorn sheep", "Alpine ibex", "hartebeest", "impala (antelope)",
|
||||
"gazelle", "arabian camel", "llama", "weasel", "mink", "European polecat",
|
||||
"black-footed ferret", "otter", "skunk", "badger", "armadillo", "three-toed sloth", "orangutan",
|
||||
"gorilla", "chimpanzee", "gibbon", "siamang", "guenon", "patas monkey", "baboon", "macaque",
|
||||
"langur", "black-and-white colobus", "proboscis monkey", "marmoset", "white-headed capuchin",
|
||||
"howler monkey", "titi monkey", "Geoffroy's spider monkey", "common squirrel monkey",
|
||||
"ring-tailed lemur", "indri", "Asian elephant", "African bush elephant", "red panda",
|
||||
"giant panda", "snoek fish", "eel", "silver salmon", "rock beauty fish", "clownfish",
|
||||
"sturgeon", "gar fish", "lionfish", "pufferfish", "abacus", "abaya", "academic gown",
|
||||
"accordion", "acoustic guitar", "aircraft carrier", "airliner", "airship", "altar", "ambulance",
|
||||
"amphibious vehicle", "analog clock", "apiary", "apron", "trash can", "assault rifle",
|
||||
"backpack", "bakery", "balance beam", "balloon", "ballpoint pen", "Band-Aid", "banjo",
|
||||
"baluster / handrail", "barbell", "barber chair", "barbershop", "barn", "barometer", "barrel",
|
||||
"wheelbarrow", "baseball", "basketball", "bassinet", "bassoon", "swimming cap", "bath towel",
|
||||
"bathtub", "station wagon", "lighthouse", "beaker", "military hat (bearskin or shako)",
|
||||
"beer bottle", "beer glass", "bell tower", "baby bib", "tandem bicycle", "bikini",
|
||||
"ring binder", "binoculars", "birdhouse", "boathouse", "bobsleigh", "bolo tie", "poke bonnet",
|
||||
"bookcase", "bookstore", "bottle cap", "hunting bow", "bow tie", "brass memorial plaque", "bra",
|
||||
"breakwater", "breastplate", "broom", "bucket", "buckle", "bulletproof vest",
|
||||
"high-speed train", "butcher shop", "taxicab", "cauldron", "candle", "cannon", "canoe",
|
||||
"can opener", "cardigan", "car mirror", "carousel", "tool kit", "cardboard box / carton",
|
||||
"car wheel", "automated teller machine", "cassette", "cassette player", "castle", "catamaran",
|
||||
"CD player", "cello", "mobile phone", "chain", "chain-link fence", "chain mail", "chainsaw",
|
||||
"storage chest", "chiffonier", "bell or wind chime", "china cabinet", "Christmas stocking",
|
||||
"church", "movie theater", "cleaver", "cliff dwelling", "cloak", "clogs", "cocktail shaker",
|
||||
"coffee mug", "coffeemaker", "spiral or coil", "combination lock", "computer keyboard",
|
||||
"candy store", "container ship", "convertible", "corkscrew", "cornet", "cowboy boot",
|
||||
"cowboy hat", "cradle", "construction crane", "crash helmet", "crate", "infant bed",
|
||||
"Crock Pot", "croquet ball", "crutch", "cuirass", "dam", "desk", "desktop computer",
|
||||
"rotary dial telephone", "diaper", "digital clock", "digital watch", "dining table",
|
||||
"dishcloth", "dishwasher", "disc brake", "dock", "dog sled", "dome", "doormat", "drilling rig",
|
||||
"drum", "drumstick", "dumbbell", "Dutch oven", "electric fan", "electric guitar",
|
||||
"electric locomotive", "entertainment center", "envelope", "espresso machine", "face powder",
|
||||
"feather boa", "filing cabinet", "fireboat", "fire truck", "fire screen", "flagpole", "flute",
|
||||
"folding chair", "football helmet", "forklift", "fountain", "fountain pen", "four-poster bed",
|
||||
"freight car", "French horn", "frying pan", "fur coat", "garbage truck",
|
||||
"gas mask or respirator", "gas pump", "goblet", "go-kart", "golf ball", "golf cart", "gondola",
|
||||
"gong", "gown", "grand piano", "greenhouse", "radiator grille", "grocery store", "guillotine",
|
||||
"hair clip", "hair spray", "half-track", "hammer", "hamper", "hair dryer", "hand-held computer",
|
||||
"handkerchief", "hard disk drive", "harmonica", "harp", "combine harvester", "hatchet",
|
||||
"holster", "home theater", "honeycomb", "hook", "hoop skirt", "gymnastic horizontal bar",
|
||||
"horse-drawn vehicle", "hourglass", "iPod", "clothes iron", "carved pumpkin", "jeans", "jeep",
|
||||
"T-shirt", "jigsaw puzzle", "rickshaw", "joystick", "kimono", "knee pad", "knot", "lab coat",
|
||||
"ladle", "lampshade", "laptop computer", "lawn mower", "lens cap", "letter opener", "library",
|
||||
"lifeboat", "lighter", "limousine", "ocean liner", "lipstick", "slip-on shoe", "lotion",
|
||||
"music speaker", "loupe magnifying glass", "sawmill", "magnetic compass", "messenger bag",
|
||||
"mailbox", "tights", "one-piece bathing suit", "manhole cover", "maraca", "marimba", "mask",
|
||||
"matchstick", "maypole", "maze", "measuring cup", "medicine cabinet", "megalith", "microphone",
|
||||
"microwave oven", "military uniform", "milk can", "minibus", "miniskirt", "minivan", "missile",
|
||||
"mitten", "mixing bowl", "mobile home", "ford model t", "modem", "monastery", "monitor",
|
||||
"moped", "mortar and pestle", "graduation cap", "mosque", "mosquito net", "vespa",
|
||||
"mountain bike", "tent", "computer mouse", "mousetrap", "moving van", "muzzle", "metal nail",
|
||||
"neck brace", "necklace", "baby pacifier", "notebook computer", "obelisk", "oboe", "ocarina",
|
||||
"odometer", "oil filter", "pipe organ", "oscilloscope", "overskirt", "bullock cart",
|
||||
"oxygen mask", "product packet / packaging", "paddle", "paddle wheel", "padlock", "paintbrush",
|
||||
"pajamas", "palace", "pan flute", "paper towel", "parachute", "parallel bars", "park bench",
|
||||
"parking meter", "railroad car", "patio", "payphone", "pedestal", "pencil case",
|
||||
"pencil sharpener", "perfume", "Petri dish", "photocopier", "plectrum", "Pickelhaube",
|
||||
"picket fence", "pickup truck", "pier", "piggy bank", "pill bottle", "pillow", "ping-pong ball",
|
||||
"pinwheel", "pirate ship", "drink pitcher", "block plane", "planetarium", "plastic bag",
|
||||
"plate rack", "farm plow", "plunger", "Polaroid camera", "pole", "police van", "poncho",
|
||||
"pool table", "soda bottle", "plant pot", "potter's wheel", "power drill", "prayer rug",
|
||||
"printer", "prison", "missile", "projector", "hockey puck", "punching bag", "purse", "quill",
|
||||
"quilt", "race car", "racket", "radiator", "radio", "radio telescope", "rain barrel",
|
||||
"recreational vehicle", "fishing casting reel", "reflex camera", "refrigerator",
|
||||
"remote control", "restaurant", "revolver", "rifle", "rocking chair", "rotisserie", "eraser",
|
||||
"rugby ball", "ruler measuring stick", "sneaker", "safe", "safety pin", "salt shaker", "sandal",
|
||||
"sarong", "saxophone", "scabbard", "weighing scale", "school bus", "schooner", "scoreboard",
|
||||
"CRT monitor", "screw", "screwdriver", "seat belt", "sewing machine", "shield", "shoe store",
|
||||
"shoji screen / room divider", "shopping basket", "shopping cart", "shovel", "shower cap",
|
||||
"shower curtain", "ski", "balaclava ski mask", "sleeping bag", "slide rule", "sliding door",
|
||||
"slot machine", "snorkel", "snowmobile", "snowplow", "soap dispenser", "soccer ball", "sock",
|
||||
"solar thermal collector", "sombrero", "soup bowl", "keyboard space bar", "space heater",
|
||||
"space shuttle", "spatula", "motorboat", "spider web", "spindle", "sports car", "spotlight",
|
||||
"stage", "steam locomotive", "through arch bridge", "steel drum", "stethoscope", "scarf",
|
||||
"stone wall", "stopwatch", "stove", "strainer", "tram", "stretcher", "couch", "stupa",
|
||||
"submarine", "suit", "sundial", "sunglasses", "sunglasses", "sunscreen", "suspension bridge",
|
||||
"mop", "sweatshirt", "swim trunks / shorts", "swing", "electrical switch", "syringe",
|
||||
"table lamp", "tank", "tape player", "teapot", "teddy bear", "television", "tennis ball",
|
||||
"thatched roof", "front curtain", "thimble", "threshing machine", "throne", "tile roof",
|
||||
"toaster", "tobacco shop", "toilet seat", "torch", "totem pole", "tow truck", "toy store",
|
||||
"tractor", "semi-trailer truck", "tray", "trench coat", "tricycle", "trimaran", "tripod",
|
||||
"triumphal arch", "trolleybus", "trombone", "hot tub", "turnstile", "typewriter keyboard",
|
||||
"umbrella", "unicycle", "upright piano", "vacuum cleaner", "vase", "vaulted or arched ceiling",
|
||||
"velvet fabric", "vending machine", "vestment", "viaduct", "violin", "volleyball",
|
||||
"waffle iron", "wall clock", "wallet", "wardrobe", "military aircraft", "sink",
|
||||
"washing machine", "water bottle", "water jug", "water tower", "whiskey jug", "whistle",
|
||||
"hair wig", "window screen", "window shade", "Windsor tie", "wine bottle", "airplane wing",
|
||||
"wok", "wooden spoon", "wool", "split-rail fence", "shipwreck", "sailboat", "yurt", "website",
|
||||
"comic book", "crossword", "traffic or street sign", "traffic light", "dust jacket", "menu",
|
||||
"plate", "guacamole", "consomme", "hot pot", "trifle", "ice cream", "popsicle", "baguette",
|
||||
"bagel", "pretzel", "cheeseburger", "hot dog", "mashed potatoes", "cabbage", "broccoli",
|
||||
"cauliflower", "zucchini", "spaghetti squash", "acorn squash", "butternut squash", "cucumber",
|
||||
"artichoke", "bell pepper", "cardoon", "mushroom", "Granny Smith apple", "strawberry", "orange",
|
||||
"lemon", "fig", "pineapple", "banana", "jackfruit", "cherimoya (custard apple)", "pomegranate",
|
||||
"hay", "carbonara", "chocolate syrup", "dough", "meatloaf", "pizza", "pot pie", "burrito",
|
||||
"red wine", "espresso", "tea cup", "eggnog", "mountain", "bubble", "cliff", "coral reef",
|
||||
"geyser", "lakeshore", "promontory", "sandbar", "beach", "valley", "volcano", "baseball player",
|
||||
"bridegroom", "scuba diver", "rapeseed", "daisy", "yellow lady's slipper", "corn", "acorn",
|
||||
"rose hip", "horse chestnut seed", "coral fungus", "agaric", "gyromitra", "stinkhorn mushroom",
|
||||
"earth star fungus", "hen of the woods mushroom", "bolete", "corn cob", "toilet paper"]
|
||||
|
||||
random.seed(1)
|
||||
k_shot = 16
|
||||
# Data loading code
|
||||
data_path = args.data_path_source
|
||||
traindir_source = os.path.join(args.data_path_source, args.src)
|
||||
traindir_target = os.path.join(args.data_path_source_t, args.src_t)
|
||||
valdir = os.path.join(args.data_path_target, args.tar)
|
||||
if not os.path.isdir(traindir_source):
|
||||
# split_train_test_images(args.data_path)
|
||||
raise ValueError('Null path of source train data!!!')
|
||||
|
||||
images = torchvision.datasets.ImageNet(data_path, split='val', transform=preprocess)
|
||||
loader = torch.utils.data.DataLoader(images, batch_size=64, num_workers=0,
|
||||
shuffle=False) # shuffle=True可以对数据进行随机读取,可以对数据进行洗牌操作(shuffling),打乱数据集内数据分布的顺序
|
||||
train_tranform = transforms.Compose([
|
||||
transforms.RandomResizedCrop(size=224, scale=(0.5, 1), interpolation=transforms.InterpolationMode.BICUBIC),
|
||||
# 随机裁剪 但是保留纵横比
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))
|
||||
])
|
||||
train_images = torchvision.datasets.ImageNet(data_path, split='train',
|
||||
transform=train_tranform)
|
||||
split_by_label_dict = defaultdict(list)
|
||||
# split_by_contexts_dict = defaultdict(list)
|
||||
# for i in range(len(imagenet_classes)):
|
||||
# split_by_contexts_dict[i]=[template.format(imagenet_classes[i]) for template in templates]
|
||||
for i in range(len(train_images.imgs)):
|
||||
split_by_label_dict[train_images.targets[i]].append(train_images.imgs[i])
|
||||
# split_by_contexts_dict[train_images.targets[i]]=[template.format(train_images.classes[train_images.targets[i]]) for template in templates]
|
||||
imgs = []
|
||||
targets = []
|
||||
# contexts=[]
|
||||
for label, items in split_by_label_dict.items():
|
||||
imgs = imgs + random.sample(items, k_shot)
|
||||
targets = targets + [label for i in range(k_shot)]
|
||||
# contexts=contexts+[split_by_context_dict[label] for i in range(k_shot)]
|
||||
|
||||
train_images.imgs = imgs
|
||||
train_images.targets = targets
|
||||
train_images.samples = imgs
|
||||
# train_images.classes= contexts
|
||||
|
||||
# train_loader = torch.utils.data.DataLoader(train_images, batch_size=64, num_workers=8, shuffle=False) # 16个样本
|
||||
train_loader_shuffle = torch.utils.data.DataLoader(train_images, batch_size=256, num_workers=0, shuffle=True)#,drop_last=True)
|
||||
|
||||
return train_loader_shuffle, loader
|
||||
233
data/prepare_data_init.py
Normal file
@@ -0,0 +1,233 @@
|
||||
import os
|
||||
import torch
|
||||
import torchvision.transforms as transforms
|
||||
import torchvision.datasets as datasets
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from collections import defaultdict
|
||||
import random
|
||||
|
||||
|
||||
def generate_dataloader(args, preprocess):
|
||||
templates = [
|
||||
"itap of a {}.",
|
||||
"a bad photo of the {}.",
|
||||
"a origami {}.",
|
||||
"a photo of the large {}.",
|
||||
"a {} in a video game.",
|
||||
"art of the {}.",
|
||||
"a photo of the small {}.",
|
||||
]
|
||||
imagenet_classes = ["tench", "goldfish", "great white shark", "tiger shark", "hammerhead shark", "electric ray",
|
||||
"stingray", "rooster", "hen", "ostrich", "brambling", "goldfinch", "house finch", "junco",
|
||||
"indigo bunting", "American robin", "bulbul", "jay", "magpie", "chickadee", "American dipper",
|
||||
"kite (bird of prey)", "bald eagle", "vulture", "great grey owl", "fire salamander",
|
||||
"smooth newt", "newt", "spotted salamander", "axolotl", "American bullfrog", "tree frog",
|
||||
"tailed frog", "loggerhead sea turtle", "leatherback sea turtle", "mud turtle", "terrapin",
|
||||
"box turtle", "banded gecko", "green iguana", "Carolina anole",
|
||||
"desert grassland whiptail lizard", "agama", "frilled-necked lizard", "alligator lizard",
|
||||
"Gila monster", "European green lizard", "chameleon", "Komodo dragon", "Nile crocodile",
|
||||
"American alligator", "triceratops", "worm snake", "ring-necked snake",
|
||||
"eastern hog-nosed snake", "smooth green snake", "kingsnake", "garter snake", "water snake",
|
||||
"vine snake", "night snake", "boa constrictor", "African rock python", "Indian cobra",
|
||||
"green mamba", "sea snake", "Saharan horned viper", "eastern diamondback rattlesnake",
|
||||
"sidewinder rattlesnake", "trilobite", "harvestman", "scorpion", "yellow garden spider",
|
||||
"barn spider", "European garden spider", "southern black widow", "tarantula", "wolf spider",
|
||||
"tick", "centipede", "black grouse", "ptarmigan", "ruffed grouse", "prairie grouse", "peafowl",
|
||||
"quail", "partridge", "african grey parrot", "macaw", "sulphur-crested cockatoo", "lorikeet",
|
||||
"coucal", "bee eater", "hornbill", "hummingbird", "jacamar", "toucan", "duck",
|
||||
"red-breasted merganser", "goose", "black swan", "tusker", "echidna", "platypus", "wallaby",
|
||||
"koala", "wombat", "jellyfish", "sea anemone", "brain coral", "flatworm", "nematode", "conch",
|
||||
"snail", "slug", "sea slug", "chiton", "chambered nautilus", "Dungeness crab", "rock crab",
|
||||
"fiddler crab", "red king crab", "American lobster", "spiny lobster", "crayfish", "hermit crab",
|
||||
"isopod", "white stork", "black stork", "spoonbill", "flamingo", "little blue heron",
|
||||
"great egret", "bittern bird", "crane bird", "limpkin", "common gallinule", "American coot",
|
||||
"bustard", "ruddy turnstone", "dunlin", "common redshank", "dowitcher", "oystercatcher",
|
||||
"pelican", "king penguin", "albatross", "grey whale", "killer whale", "dugong", "sea lion",
|
||||
"Chihuahua", "Japanese Chin", "Maltese", "Pekingese", "Shih Tzu", "King Charles Spaniel",
|
||||
"Papillon", "toy terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset Hound", "Beagle",
|
||||
"Bloodhound", "Bluetick Coonhound", "Black and Tan Coonhound", "Treeing Walker Coonhound",
|
||||
"English foxhound", "Redbone Coonhound", "borzoi", "Irish Wolfhound", "Italian Greyhound",
|
||||
"Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound",
|
||||
"Weimaraner", "Staffordshire Bull Terrier", "American Staffordshire Terrier",
|
||||
"Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier",
|
||||
"Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire Fox Terrier",
|
||||
"Lakeland Terrier", "Sealyham Terrier", "Airedale Terrier", "Cairn Terrier",
|
||||
"Australian Terrier", "Dandie Dinmont Terrier", "Boston Terrier", "Miniature Schnauzer",
|
||||
"Giant Schnauzer", "Standard Schnauzer", "Scottish Terrier", "Tibetan Terrier",
|
||||
"Australian Silky Terrier", "Soft-coated Wheaten Terrier", "West Highland White Terrier",
|
||||
"Lhasa Apso", "Flat-Coated Retriever", "Curly-coated Retriever", "Golden Retriever",
|
||||
"Labrador Retriever", "Chesapeake Bay Retriever", "German Shorthaired Pointer", "Vizsla",
|
||||
"English Setter", "Irish Setter", "Gordon Setter", "Brittany dog", "Clumber Spaniel",
|
||||
"English Springer Spaniel", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel",
|
||||
"Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael dog", "Malinois", "Briard",
|
||||
"Australian Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "collie",
|
||||
"Border Collie", "Bouvier des Flandres dog", "Rottweiler", "German Shepherd Dog", "Dobermann",
|
||||
"Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog",
|
||||
"Appenzeller Sennenhund", "Entlebucher Sennenhund", "Boxer", "Bullmastiff", "Tibetan Mastiff",
|
||||
"French Bulldog", "Great Dane", "St. Bernard", "husky", "Alaskan Malamute", "Siberian Husky",
|
||||
"Dalmatian", "Affenpinscher", "Basenji", "pug", "Leonberger", "Newfoundland dog",
|
||||
"Great Pyrenees dog", "Samoyed", "Pomeranian", "Chow Chow", "Keeshond", "brussels griffon",
|
||||
"Pembroke Welsh Corgi", "Cardigan Welsh Corgi", "Toy Poodle", "Miniature Poodle",
|
||||
"Standard Poodle", "Mexican hairless dog (xoloitzcuintli)", "grey wolf", "Alaskan tundra wolf",
|
||||
"red wolf or maned wolf", "coyote", "dingo", "dhole", "African wild dog", "hyena", "red fox",
|
||||
"kit fox", "Arctic fox", "grey fox", "tabby cat", "tiger cat", "Persian cat", "Siamese cat",
|
||||
"Egyptian Mau", "cougar", "lynx", "leopard", "snow leopard", "jaguar", "lion", "tiger",
|
||||
"cheetah", "brown bear", "American black bear", "polar bear", "sloth bear", "mongoose",
|
||||
"meerkat", "tiger beetle", "ladybug", "ground beetle", "longhorn beetle", "leaf beetle",
|
||||
"dung beetle", "rhinoceros beetle", "weevil", "fly", "bee", "ant", "grasshopper",
|
||||
"cricket insect", "stick insect", "cockroach", "praying mantis", "cicada", "leafhopper",
|
||||
"lacewing", "dragonfly", "damselfly", "red admiral butterfly", "ringlet butterfly",
|
||||
"monarch butterfly", "small white butterfly", "sulphur butterfly", "gossamer-winged butterfly",
|
||||
"starfish", "sea urchin", "sea cucumber", "cottontail rabbit", "hare", "Angora rabbit",
|
||||
"hamster", "porcupine", "fox squirrel", "marmot", "beaver", "guinea pig", "common sorrel horse",
|
||||
"zebra", "pig", "wild boar", "warthog", "hippopotamus", "ox", "water buffalo", "bison",
|
||||
"ram (adult male sheep)", "bighorn sheep", "Alpine ibex", "hartebeest", "impala (antelope)",
|
||||
"gazelle", "arabian camel", "llama", "weasel", "mink", "European polecat",
|
||||
"black-footed ferret", "otter", "skunk", "badger", "armadillo", "three-toed sloth", "orangutan",
|
||||
"gorilla", "chimpanzee", "gibbon", "siamang", "guenon", "patas monkey", "baboon", "macaque",
|
||||
"langur", "black-and-white colobus", "proboscis monkey", "marmoset", "white-headed capuchin",
|
||||
"howler monkey", "titi monkey", "Geoffroy's spider monkey", "common squirrel monkey",
|
||||
"ring-tailed lemur", "indri", "Asian elephant", "African bush elephant", "red panda",
|
||||
"giant panda", "snoek fish", "eel", "silver salmon", "rock beauty fish", "clownfish",
|
||||
"sturgeon", "gar fish", "lionfish", "pufferfish", "abacus", "abaya", "academic gown",
|
||||
"accordion", "acoustic guitar", "aircraft carrier", "airliner", "airship", "altar", "ambulance",
|
||||
"amphibious vehicle", "analog clock", "apiary", "apron", "trash can", "assault rifle",
|
||||
"backpack", "bakery", "balance beam", "balloon", "ballpoint pen", "Band-Aid", "banjo",
|
||||
"baluster / handrail", "barbell", "barber chair", "barbershop", "barn", "barometer", "barrel",
|
||||
"wheelbarrow", "baseball", "basketball", "bassinet", "bassoon", "swimming cap", "bath towel",
|
||||
"bathtub", "station wagon", "lighthouse", "beaker", "military hat (bearskin or shako)",
|
||||
"beer bottle", "beer glass", "bell tower", "baby bib", "tandem bicycle", "bikini",
|
||||
"ring binder", "binoculars", "birdhouse", "boathouse", "bobsleigh", "bolo tie", "poke bonnet",
|
||||
"bookcase", "bookstore", "bottle cap", "hunting bow", "bow tie", "brass memorial plaque", "bra",
|
||||
"breakwater", "breastplate", "broom", "bucket", "buckle", "bulletproof vest",
|
||||
"high-speed train", "butcher shop", "taxicab", "cauldron", "candle", "cannon", "canoe",
|
||||
"can opener", "cardigan", "car mirror", "carousel", "tool kit", "cardboard box / carton",
|
||||
"car wheel", "automated teller machine", "cassette", "cassette player", "castle", "catamaran",
|
||||
"CD player", "cello", "mobile phone", "chain", "chain-link fence", "chain mail", "chainsaw",
|
||||
"storage chest", "chiffonier", "bell or wind chime", "china cabinet", "Christmas stocking",
|
||||
"church", "movie theater", "cleaver", "cliff dwelling", "cloak", "clogs", "cocktail shaker",
|
||||
"coffee mug", "coffeemaker", "spiral or coil", "combination lock", "computer keyboard",
|
||||
"candy store", "container ship", "convertible", "corkscrew", "cornet", "cowboy boot",
|
||||
"cowboy hat", "cradle", "construction crane", "crash helmet", "crate", "infant bed",
|
||||
"Crock Pot", "croquet ball", "crutch", "cuirass", "dam", "desk", "desktop computer",
|
||||
"rotary dial telephone", "diaper", "digital clock", "digital watch", "dining table",
|
||||
"dishcloth", "dishwasher", "disc brake", "dock", "dog sled", "dome", "doormat", "drilling rig",
|
||||
"drum", "drumstick", "dumbbell", "Dutch oven", "electric fan", "electric guitar",
|
||||
"electric locomotive", "entertainment center", "envelope", "espresso machine", "face powder",
|
||||
"feather boa", "filing cabinet", "fireboat", "fire truck", "fire screen", "flagpole", "flute",
|
||||
"folding chair", "football helmet", "forklift", "fountain", "fountain pen", "four-poster bed",
|
||||
"freight car", "French horn", "frying pan", "fur coat", "garbage truck",
|
||||
"gas mask or respirator", "gas pump", "goblet", "go-kart", "golf ball", "golf cart", "gondola",
|
||||
"gong", "gown", "grand piano", "greenhouse", "radiator grille", "grocery store", "guillotine",
|
||||
"hair clip", "hair spray", "half-track", "hammer", "hamper", "hair dryer", "hand-held computer",
|
||||
"handkerchief", "hard disk drive", "harmonica", "harp", "combine harvester", "hatchet",
|
||||
"holster", "home theater", "honeycomb", "hook", "hoop skirt", "gymnastic horizontal bar",
|
||||
"horse-drawn vehicle", "hourglass", "iPod", "clothes iron", "carved pumpkin", "jeans", "jeep",
|
||||
"T-shirt", "jigsaw puzzle", "rickshaw", "joystick", "kimono", "knee pad", "knot", "lab coat",
|
||||
"ladle", "lampshade", "laptop computer", "lawn mower", "lens cap", "letter opener", "library",
|
||||
"lifeboat", "lighter", "limousine", "ocean liner", "lipstick", "slip-on shoe", "lotion",
|
||||
"music speaker", "loupe magnifying glass", "sawmill", "magnetic compass", "messenger bag",
|
||||
"mailbox", "tights", "one-piece bathing suit", "manhole cover", "maraca", "marimba", "mask",
|
||||
"matchstick", "maypole", "maze", "measuring cup", "medicine cabinet", "megalith", "microphone",
|
||||
"microwave oven", "military uniform", "milk can", "minibus", "miniskirt", "minivan", "missile",
|
||||
"mitten", "mixing bowl", "mobile home", "ford model t", "modem", "monastery", "monitor",
|
||||
"moped", "mortar and pestle", "graduation cap", "mosque", "mosquito net", "vespa",
|
||||
"mountain bike", "tent", "computer mouse", "mousetrap", "moving van", "muzzle", "metal nail",
|
||||
"neck brace", "necklace", "baby pacifier", "notebook computer", "obelisk", "oboe", "ocarina",
|
||||
"odometer", "oil filter", "pipe organ", "oscilloscope", "overskirt", "bullock cart",
|
||||
"oxygen mask", "product packet / packaging", "paddle", "paddle wheel", "padlock", "paintbrush",
|
||||
"pajamas", "palace", "pan flute", "paper towel", "parachute", "parallel bars", "park bench",
|
||||
"parking meter", "railroad car", "patio", "payphone", "pedestal", "pencil case",
|
||||
"pencil sharpener", "perfume", "Petri dish", "photocopier", "plectrum", "Pickelhaube",
|
||||
"picket fence", "pickup truck", "pier", "piggy bank", "pill bottle", "pillow", "ping-pong ball",
|
||||
"pinwheel", "pirate ship", "drink pitcher", "block plane", "planetarium", "plastic bag",
|
||||
"plate rack", "farm plow", "plunger", "Polaroid camera", "pole", "police van", "poncho",
|
||||
"pool table", "soda bottle", "plant pot", "potter's wheel", "power drill", "prayer rug",
|
||||
"printer", "prison", "missile", "projector", "hockey puck", "punching bag", "purse", "quill",
|
||||
"quilt", "race car", "racket", "radiator", "radio", "radio telescope", "rain barrel",
|
||||
"recreational vehicle", "fishing casting reel", "reflex camera", "refrigerator",
|
||||
"remote control", "restaurant", "revolver", "rifle", "rocking chair", "rotisserie", "eraser",
|
||||
"rugby ball", "ruler measuring stick", "sneaker", "safe", "safety pin", "salt shaker", "sandal",
|
||||
"sarong", "saxophone", "scabbard", "weighing scale", "school bus", "schooner", "scoreboard",
|
||||
"CRT monitor", "screw", "screwdriver", "seat belt", "sewing machine", "shield", "shoe store",
|
||||
"shoji screen / room divider", "shopping basket", "shopping cart", "shovel", "shower cap",
|
||||
"shower curtain", "ski", "balaclava ski mask", "sleeping bag", "slide rule", "sliding door",
|
||||
"slot machine", "snorkel", "snowmobile", "snowplow", "soap dispenser", "soccer ball", "sock",
|
||||
"solar thermal collector", "sombrero", "soup bowl", "keyboard space bar", "space heater",
|
||||
"space shuttle", "spatula", "motorboat", "spider web", "spindle", "sports car", "spotlight",
|
||||
"stage", "steam locomotive", "through arch bridge", "steel drum", "stethoscope", "scarf",
|
||||
"stone wall", "stopwatch", "stove", "strainer", "tram", "stretcher", "couch", "stupa",
|
||||
"submarine", "suit", "sundial", "sunglasses", "sunglasses", "sunscreen", "suspension bridge",
|
||||
"mop", "sweatshirt", "swim trunks / shorts", "swing", "electrical switch", "syringe",
|
||||
"table lamp", "tank", "tape player", "teapot", "teddy bear", "television", "tennis ball",
|
||||
"thatched roof", "front curtain", "thimble", "threshing machine", "throne", "tile roof",
|
||||
"toaster", "tobacco shop", "toilet seat", "torch", "totem pole", "tow truck", "toy store",
|
||||
"tractor", "semi-trailer truck", "tray", "trench coat", "tricycle", "trimaran", "tripod",
|
||||
"triumphal arch", "trolleybus", "trombone", "hot tub", "turnstile", "typewriter keyboard",
|
||||
"umbrella", "unicycle", "upright piano", "vacuum cleaner", "vase", "vaulted or arched ceiling",
|
||||
"velvet fabric", "vending machine", "vestment", "viaduct", "violin", "volleyball",
|
||||
"waffle iron", "wall clock", "wallet", "wardrobe", "military aircraft", "sink",
|
||||
"washing machine", "water bottle", "water jug", "water tower", "whiskey jug", "whistle",
|
||||
"hair wig", "window screen", "window shade", "Windsor tie", "wine bottle", "airplane wing",
|
||||
"wok", "wooden spoon", "wool", "split-rail fence", "shipwreck", "sailboat", "yurt", "website",
|
||||
"comic book", "crossword", "traffic or street sign", "traffic light", "dust jacket", "menu",
|
||||
"plate", "guacamole", "consomme", "hot pot", "trifle", "ice cream", "popsicle", "baguette",
|
||||
"bagel", "pretzel", "cheeseburger", "hot dog", "mashed potatoes", "cabbage", "broccoli",
|
||||
"cauliflower", "zucchini", "spaghetti squash", "acorn squash", "butternut squash", "cucumber",
|
||||
"artichoke", "bell pepper", "cardoon", "mushroom", "Granny Smith apple", "strawberry", "orange",
|
||||
"lemon", "fig", "pineapple", "banana", "jackfruit", "cherimoya (custard apple)", "pomegranate",
|
||||
"hay", "carbonara", "chocolate syrup", "dough", "meatloaf", "pizza", "pot pie", "burrito",
|
||||
"red wine", "espresso", "tea cup", "eggnog", "mountain", "bubble", "cliff", "coral reef",
|
||||
"geyser", "lakeshore", "promontory", "sandbar", "beach", "valley", "volcano", "baseball player",
|
||||
"bridegroom", "scuba diver", "rapeseed", "daisy", "yellow lady's slipper", "corn", "acorn",
|
||||
"rose hip", "horse chestnut seed", "coral fungus", "agaric", "gyromitra", "stinkhorn mushroom",
|
||||
"earth star fungus", "hen of the woods mushroom", "bolete", "corn cob", "toilet paper"]
|
||||
|
||||
random.seed(1)
|
||||
k_shot = 16
|
||||
# Data loading code
|
||||
data_path = args.data_path_source
|
||||
traindir_source = os.path.join(args.data_path_source, args.src)
|
||||
traindir_target = os.path.join(args.data_path_source_t, args.src_t)
|
||||
valdir = os.path.join(args.data_path_target, args.tar)
|
||||
if not os.path.isdir(traindir_source):
|
||||
# split_train_test_images(args.data_path)
|
||||
raise ValueError('Null path of source train data!!!')
|
||||
|
||||
images = torchvision.datasets.ImageNet(data_path, split='val', transform=preprocess)
|
||||
loader = torch.utils.data.DataLoader(images, batch_size=64, num_workers=8,
|
||||
shuffle=False) # shuffle=True可以对数据进行随机读取,可以对数据进行洗牌操作(shuffling),打乱数据集内数据分布的顺序
|
||||
train_tranform = transforms.Compose([
|
||||
transforms.RandomResizedCrop(size=224, scale=(0.5, 1), interpolation=transforms.InterpolationMode.BICUBIC),
|
||||
# 随机裁剪 但是保留纵横比
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))
|
||||
])
|
||||
train_images = torchvision.datasets.ImageNet(data_path, split='train',
|
||||
transform=train_tranform)
|
||||
split_by_label_dict = defaultdict(list)
|
||||
# split_by_contexts_dict = defaultdict(list)
|
||||
# for i in range(len(imagenet_classes)):
|
||||
# split_by_contexts_dict[i]=[template.format(imagenet_classes[i]) for template in templates]
|
||||
for i in range(len(train_images.imgs)):
|
||||
split_by_label_dict[train_images.targets[i]].append(train_images.imgs[i])
|
||||
# split_by_contexts_dict[train_images.targets[i]]=[template.format(train_images.classes[train_images.targets[i]]) for template in templates]
|
||||
imgs = []
|
||||
targets = []
|
||||
# contexts=[]
|
||||
for label, items in split_by_label_dict.items():
|
||||
imgs = imgs + random.sample(items, k_shot)
|
||||
targets = targets + [label for i in range(k_shot)]
|
||||
# contexts=contexts+[split_by_context_dict[label] for i in range(k_shot)]
|
||||
|
||||
train_images.imgs = imgs
|
||||
train_images.targets = targets
|
||||
train_images.samples = imgs
|
||||
# train_images.classes= contexts
|
||||
|
||||
train_loader = torch.utils.data.DataLoader(train_images, batch_size=256, num_workers=8, shuffle=False) # 16个样本
|
||||
train_loader_shuffle = torch.utils.data.DataLoader(train_images, batch_size=256, num_workers=8, shuffle=True)#,drop_last=True)
|
||||
|
||||
return train_loader_shuffle, loader,train_loader
|
||||
233
data/prepare_data_shot1.py
Normal file
@@ -0,0 +1,233 @@
|
||||
import os
|
||||
import torch
|
||||
import torchvision.transforms as transforms
|
||||
import torchvision.datasets as datasets
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from collections import defaultdict
|
||||
import random
|
||||
|
||||
|
||||
def generate_dataloader(args, preprocess):
|
||||
templates = [
|
||||
"itap of a {}.",
|
||||
"a bad photo of the {}.",
|
||||
"a origami {}.",
|
||||
"a photo of the large {}.",
|
||||
"a {} in a video game.",
|
||||
"art of the {}.",
|
||||
"a photo of the small {}.",
|
||||
]
|
||||
imagenet_classes = ["tench", "goldfish", "great white shark", "tiger shark", "hammerhead shark", "electric ray",
|
||||
"stingray", "rooster", "hen", "ostrich", "brambling", "goldfinch", "house finch", "junco",
|
||||
"indigo bunting", "American robin", "bulbul", "jay", "magpie", "chickadee", "American dipper",
|
||||
"kite (bird of prey)", "bald eagle", "vulture", "great grey owl", "fire salamander",
|
||||
"smooth newt", "newt", "spotted salamander", "axolotl", "American bullfrog", "tree frog",
|
||||
"tailed frog", "loggerhead sea turtle", "leatherback sea turtle", "mud turtle", "terrapin",
|
||||
"box turtle", "banded gecko", "green iguana", "Carolina anole",
|
||||
"desert grassland whiptail lizard", "agama", "frilled-necked lizard", "alligator lizard",
|
||||
"Gila monster", "European green lizard", "chameleon", "Komodo dragon", "Nile crocodile",
|
||||
"American alligator", "triceratops", "worm snake", "ring-necked snake",
|
||||
"eastern hog-nosed snake", "smooth green snake", "kingsnake", "garter snake", "water snake",
|
||||
"vine snake", "night snake", "boa constrictor", "African rock python", "Indian cobra",
|
||||
"green mamba", "sea snake", "Saharan horned viper", "eastern diamondback rattlesnake",
|
||||
"sidewinder rattlesnake", "trilobite", "harvestman", "scorpion", "yellow garden spider",
|
||||
"barn spider", "European garden spider", "southern black widow", "tarantula", "wolf spider",
|
||||
"tick", "centipede", "black grouse", "ptarmigan", "ruffed grouse", "prairie grouse", "peafowl",
|
||||
"quail", "partridge", "african grey parrot", "macaw", "sulphur-crested cockatoo", "lorikeet",
|
||||
"coucal", "bee eater", "hornbill", "hummingbird", "jacamar", "toucan", "duck",
|
||||
"red-breasted merganser", "goose", "black swan", "tusker", "echidna", "platypus", "wallaby",
|
||||
"koala", "wombat", "jellyfish", "sea anemone", "brain coral", "flatworm", "nematode", "conch",
|
||||
"snail", "slug", "sea slug", "chiton", "chambered nautilus", "Dungeness crab", "rock crab",
|
||||
"fiddler crab", "red king crab", "American lobster", "spiny lobster", "crayfish", "hermit crab",
|
||||
"isopod", "white stork", "black stork", "spoonbill", "flamingo", "little blue heron",
|
||||
"great egret", "bittern bird", "crane bird", "limpkin", "common gallinule", "American coot",
|
||||
"bustard", "ruddy turnstone", "dunlin", "common redshank", "dowitcher", "oystercatcher",
|
||||
"pelican", "king penguin", "albatross", "grey whale", "killer whale", "dugong", "sea lion",
|
||||
"Chihuahua", "Japanese Chin", "Maltese", "Pekingese", "Shih Tzu", "King Charles Spaniel",
|
||||
"Papillon", "toy terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset Hound", "Beagle",
|
||||
"Bloodhound", "Bluetick Coonhound", "Black and Tan Coonhound", "Treeing Walker Coonhound",
|
||||
"English foxhound", "Redbone Coonhound", "borzoi", "Irish Wolfhound", "Italian Greyhound",
|
||||
"Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound",
|
||||
"Weimaraner", "Staffordshire Bull Terrier", "American Staffordshire Terrier",
|
||||
"Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier",
|
||||
"Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire Fox Terrier",
|
||||
"Lakeland Terrier", "Sealyham Terrier", "Airedale Terrier", "Cairn Terrier",
|
||||
"Australian Terrier", "Dandie Dinmont Terrier", "Boston Terrier", "Miniature Schnauzer",
|
||||
"Giant Schnauzer", "Standard Schnauzer", "Scottish Terrier", "Tibetan Terrier",
|
||||
"Australian Silky Terrier", "Soft-coated Wheaten Terrier", "West Highland White Terrier",
|
||||
"Lhasa Apso", "Flat-Coated Retriever", "Curly-coated Retriever", "Golden Retriever",
|
||||
"Labrador Retriever", "Chesapeake Bay Retriever", "German Shorthaired Pointer", "Vizsla",
|
||||
"English Setter", "Irish Setter", "Gordon Setter", "Brittany dog", "Clumber Spaniel",
|
||||
"English Springer Spaniel", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel",
|
||||
"Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael dog", "Malinois", "Briard",
|
||||
"Australian Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "collie",
|
||||
"Border Collie", "Bouvier des Flandres dog", "Rottweiler", "German Shepherd Dog", "Dobermann",
|
||||
"Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog",
|
||||
"Appenzeller Sennenhund", "Entlebucher Sennenhund", "Boxer", "Bullmastiff", "Tibetan Mastiff",
|
||||
"French Bulldog", "Great Dane", "St. Bernard", "husky", "Alaskan Malamute", "Siberian Husky",
|
||||
"Dalmatian", "Affenpinscher", "Basenji", "pug", "Leonberger", "Newfoundland dog",
|
||||
"Great Pyrenees dog", "Samoyed", "Pomeranian", "Chow Chow", "Keeshond", "brussels griffon",
|
||||
"Pembroke Welsh Corgi", "Cardigan Welsh Corgi", "Toy Poodle", "Miniature Poodle",
|
||||
"Standard Poodle", "Mexican hairless dog (xoloitzcuintli)", "grey wolf", "Alaskan tundra wolf",
|
||||
"red wolf or maned wolf", "coyote", "dingo", "dhole", "African wild dog", "hyena", "red fox",
|
||||
"kit fox", "Arctic fox", "grey fox", "tabby cat", "tiger cat", "Persian cat", "Siamese cat",
|
||||
"Egyptian Mau", "cougar", "lynx", "leopard", "snow leopard", "jaguar", "lion", "tiger",
|
||||
"cheetah", "brown bear", "American black bear", "polar bear", "sloth bear", "mongoose",
|
||||
"meerkat", "tiger beetle", "ladybug", "ground beetle", "longhorn beetle", "leaf beetle",
|
||||
"dung beetle", "rhinoceros beetle", "weevil", "fly", "bee", "ant", "grasshopper",
|
||||
"cricket insect", "stick insect", "cockroach", "praying mantis", "cicada", "leafhopper",
|
||||
"lacewing", "dragonfly", "damselfly", "red admiral butterfly", "ringlet butterfly",
|
||||
"monarch butterfly", "small white butterfly", "sulphur butterfly", "gossamer-winged butterfly",
|
||||
"starfish", "sea urchin", "sea cucumber", "cottontail rabbit", "hare", "Angora rabbit",
|
||||
"hamster", "porcupine", "fox squirrel", "marmot", "beaver", "guinea pig", "common sorrel horse",
|
||||
"zebra", "pig", "wild boar", "warthog", "hippopotamus", "ox", "water buffalo", "bison",
|
||||
"ram (adult male sheep)", "bighorn sheep", "Alpine ibex", "hartebeest", "impala (antelope)",
|
||||
"gazelle", "arabian camel", "llama", "weasel", "mink", "European polecat",
|
||||
"black-footed ferret", "otter", "skunk", "badger", "armadillo", "three-toed sloth", "orangutan",
|
||||
"gorilla", "chimpanzee", "gibbon", "siamang", "guenon", "patas monkey", "baboon", "macaque",
|
||||
"langur", "black-and-white colobus", "proboscis monkey", "marmoset", "white-headed capuchin",
|
||||
"howler monkey", "titi monkey", "Geoffroy's spider monkey", "common squirrel monkey",
|
||||
"ring-tailed lemur", "indri", "Asian elephant", "African bush elephant", "red panda",
|
||||
"giant panda", "snoek fish", "eel", "silver salmon", "rock beauty fish", "clownfish",
|
||||
"sturgeon", "gar fish", "lionfish", "pufferfish", "abacus", "abaya", "academic gown",
|
||||
"accordion", "acoustic guitar", "aircraft carrier", "airliner", "airship", "altar", "ambulance",
|
||||
"amphibious vehicle", "analog clock", "apiary", "apron", "trash can", "assault rifle",
|
||||
"backpack", "bakery", "balance beam", "balloon", "ballpoint pen", "Band-Aid", "banjo",
|
||||
"baluster / handrail", "barbell", "barber chair", "barbershop", "barn", "barometer", "barrel",
|
||||
"wheelbarrow", "baseball", "basketball", "bassinet", "bassoon", "swimming cap", "bath towel",
|
||||
"bathtub", "station wagon", "lighthouse", "beaker", "military hat (bearskin or shako)",
|
||||
"beer bottle", "beer glass", "bell tower", "baby bib", "tandem bicycle", "bikini",
|
||||
"ring binder", "binoculars", "birdhouse", "boathouse", "bobsleigh", "bolo tie", "poke bonnet",
|
||||
"bookcase", "bookstore", "bottle cap", "hunting bow", "bow tie", "brass memorial plaque", "bra",
|
||||
"breakwater", "breastplate", "broom", "bucket", "buckle", "bulletproof vest",
|
||||
"high-speed train", "butcher shop", "taxicab", "cauldron", "candle", "cannon", "canoe",
|
||||
"can opener", "cardigan", "car mirror", "carousel", "tool kit", "cardboard box / carton",
|
||||
"car wheel", "automated teller machine", "cassette", "cassette player", "castle", "catamaran",
|
||||
"CD player", "cello", "mobile phone", "chain", "chain-link fence", "chain mail", "chainsaw",
|
||||
"storage chest", "chiffonier", "bell or wind chime", "china cabinet", "Christmas stocking",
|
||||
"church", "movie theater", "cleaver", "cliff dwelling", "cloak", "clogs", "cocktail shaker",
|
||||
"coffee mug", "coffeemaker", "spiral or coil", "combination lock", "computer keyboard",
|
||||
"candy store", "container ship", "convertible", "corkscrew", "cornet", "cowboy boot",
|
||||
"cowboy hat", "cradle", "construction crane", "crash helmet", "crate", "infant bed",
|
||||
"Crock Pot", "croquet ball", "crutch", "cuirass", "dam", "desk", "desktop computer",
|
||||
"rotary dial telephone", "diaper", "digital clock", "digital watch", "dining table",
|
||||
"dishcloth", "dishwasher", "disc brake", "dock", "dog sled", "dome", "doormat", "drilling rig",
|
||||
"drum", "drumstick", "dumbbell", "Dutch oven", "electric fan", "electric guitar",
|
||||
"electric locomotive", "entertainment center", "envelope", "espresso machine", "face powder",
|
||||
"feather boa", "filing cabinet", "fireboat", "fire truck", "fire screen", "flagpole", "flute",
|
||||
"folding chair", "football helmet", "forklift", "fountain", "fountain pen", "four-poster bed",
|
||||
"freight car", "French horn", "frying pan", "fur coat", "garbage truck",
|
||||
"gas mask or respirator", "gas pump", "goblet", "go-kart", "golf ball", "golf cart", "gondola",
|
||||
"gong", "gown", "grand piano", "greenhouse", "radiator grille", "grocery store", "guillotine",
|
||||
"hair clip", "hair spray", "half-track", "hammer", "hamper", "hair dryer", "hand-held computer",
|
||||
"handkerchief", "hard disk drive", "harmonica", "harp", "combine harvester", "hatchet",
|
||||
"holster", "home theater", "honeycomb", "hook", "hoop skirt", "gymnastic horizontal bar",
|
||||
"horse-drawn vehicle", "hourglass", "iPod", "clothes iron", "carved pumpkin", "jeans", "jeep",
|
||||
"T-shirt", "jigsaw puzzle", "rickshaw", "joystick", "kimono", "knee pad", "knot", "lab coat",
|
||||
"ladle", "lampshade", "laptop computer", "lawn mower", "lens cap", "letter opener", "library",
|
||||
"lifeboat", "lighter", "limousine", "ocean liner", "lipstick", "slip-on shoe", "lotion",
|
||||
"music speaker", "loupe magnifying glass", "sawmill", "magnetic compass", "messenger bag",
|
||||
"mailbox", "tights", "one-piece bathing suit", "manhole cover", "maraca", "marimba", "mask",
|
||||
"matchstick", "maypole", "maze", "measuring cup", "medicine cabinet", "megalith", "microphone",
|
||||
"microwave oven", "military uniform", "milk can", "minibus", "miniskirt", "minivan", "missile",
|
||||
"mitten", "mixing bowl", "mobile home", "ford model t", "modem", "monastery", "monitor",
|
||||
"moped", "mortar and pestle", "graduation cap", "mosque", "mosquito net", "vespa",
|
||||
"mountain bike", "tent", "computer mouse", "mousetrap", "moving van", "muzzle", "metal nail",
|
||||
"neck brace", "necklace", "baby pacifier", "notebook computer", "obelisk", "oboe", "ocarina",
|
||||
"odometer", "oil filter", "pipe organ", "oscilloscope", "overskirt", "bullock cart",
|
||||
"oxygen mask", "product packet / packaging", "paddle", "paddle wheel", "padlock", "paintbrush",
|
||||
"pajamas", "palace", "pan flute", "paper towel", "parachute", "parallel bars", "park bench",
|
||||
"parking meter", "railroad car", "patio", "payphone", "pedestal", "pencil case",
|
||||
"pencil sharpener", "perfume", "Petri dish", "photocopier", "plectrum", "Pickelhaube",
|
||||
"picket fence", "pickup truck", "pier", "piggy bank", "pill bottle", "pillow", "ping-pong ball",
|
||||
"pinwheel", "pirate ship", "drink pitcher", "block plane", "planetarium", "plastic bag",
|
||||
"plate rack", "farm plow", "plunger", "Polaroid camera", "pole", "police van", "poncho",
|
||||
"pool table", "soda bottle", "plant pot", "potter's wheel", "power drill", "prayer rug",
|
||||
"printer", "prison", "missile", "projector", "hockey puck", "punching bag", "purse", "quill",
|
||||
"quilt", "race car", "racket", "radiator", "radio", "radio telescope", "rain barrel",
|
||||
"recreational vehicle", "fishing casting reel", "reflex camera", "refrigerator",
|
||||
"remote control", "restaurant", "revolver", "rifle", "rocking chair", "rotisserie", "eraser",
|
||||
"rugby ball", "ruler measuring stick", "sneaker", "safe", "safety pin", "salt shaker", "sandal",
|
||||
"sarong", "saxophone", "scabbard", "weighing scale", "school bus", "schooner", "scoreboard",
|
||||
"CRT monitor", "screw", "screwdriver", "seat belt", "sewing machine", "shield", "shoe store",
|
||||
"shoji screen / room divider", "shopping basket", "shopping cart", "shovel", "shower cap",
|
||||
"shower curtain", "ski", "balaclava ski mask", "sleeping bag", "slide rule", "sliding door",
|
||||
"slot machine", "snorkel", "snowmobile", "snowplow", "soap dispenser", "soccer ball", "sock",
|
||||
"solar thermal collector", "sombrero", "soup bowl", "keyboard space bar", "space heater",
|
||||
"space shuttle", "spatula", "motorboat", "spider web", "spindle", "sports car", "spotlight",
|
||||
"stage", "steam locomotive", "through arch bridge", "steel drum", "stethoscope", "scarf",
|
||||
"stone wall", "stopwatch", "stove", "strainer", "tram", "stretcher", "couch", "stupa",
|
||||
"submarine", "suit", "sundial", "sunglasses", "sunglasses", "sunscreen", "suspension bridge",
|
||||
"mop", "sweatshirt", "swim trunks / shorts", "swing", "electrical switch", "syringe",
|
||||
"table lamp", "tank", "tape player", "teapot", "teddy bear", "television", "tennis ball",
|
||||
"thatched roof", "front curtain", "thimble", "threshing machine", "throne", "tile roof",
|
||||
"toaster", "tobacco shop", "toilet seat", "torch", "totem pole", "tow truck", "toy store",
|
||||
"tractor", "semi-trailer truck", "tray", "trench coat", "tricycle", "trimaran", "tripod",
|
||||
"triumphal arch", "trolleybus", "trombone", "hot tub", "turnstile", "typewriter keyboard",
|
||||
"umbrella", "unicycle", "upright piano", "vacuum cleaner", "vase", "vaulted or arched ceiling",
|
||||
"velvet fabric", "vending machine", "vestment", "viaduct", "violin", "volleyball",
|
||||
"waffle iron", "wall clock", "wallet", "wardrobe", "military aircraft", "sink",
|
||||
"washing machine", "water bottle", "water jug", "water tower", "whiskey jug", "whistle",
|
||||
"hair wig", "window screen", "window shade", "Windsor tie", "wine bottle", "airplane wing",
|
||||
"wok", "wooden spoon", "wool", "split-rail fence", "shipwreck", "sailboat", "yurt", "website",
|
||||
"comic book", "crossword", "traffic or street sign", "traffic light", "dust jacket", "menu",
|
||||
"plate", "guacamole", "consomme", "hot pot", "trifle", "ice cream", "popsicle", "baguette",
|
||||
"bagel", "pretzel", "cheeseburger", "hot dog", "mashed potatoes", "cabbage", "broccoli",
|
||||
"cauliflower", "zucchini", "spaghetti squash", "acorn squash", "butternut squash", "cucumber",
|
||||
"artichoke", "bell pepper", "cardoon", "mushroom", "Granny Smith apple", "strawberry", "orange",
|
||||
"lemon", "fig", "pineapple", "banana", "jackfruit", "cherimoya (custard apple)", "pomegranate",
|
||||
"hay", "carbonara", "chocolate syrup", "dough", "meatloaf", "pizza", "pot pie", "burrito",
|
||||
"red wine", "espresso", "tea cup", "eggnog", "mountain", "bubble", "cliff", "coral reef",
|
||||
"geyser", "lakeshore", "promontory", "sandbar", "beach", "valley", "volcano", "baseball player",
|
||||
"bridegroom", "scuba diver", "rapeseed", "daisy", "yellow lady's slipper", "corn", "acorn",
|
||||
"rose hip", "horse chestnut seed", "coral fungus", "agaric", "gyromitra", "stinkhorn mushroom",
|
||||
"earth star fungus", "hen of the woods mushroom", "bolete", "corn cob", "toilet paper"]
|
||||
|
||||
random.seed(1)
|
||||
k_shot = 1
|
||||
# Data loading code
|
||||
data_path = args.data_path_source
|
||||
traindir_source = os.path.join(args.data_path_source, args.src)
|
||||
traindir_target = os.path.join(args.data_path_source_t, args.src_t)
|
||||
valdir = os.path.join(args.data_path_target, args.tar)
|
||||
if not os.path.isdir(traindir_source):
|
||||
# split_train_test_images(args.data_path)
|
||||
raise ValueError('Null path of source train data!!!')
|
||||
|
||||
images = torchvision.datasets.ImageNet(data_path, split='val', transform=preprocess)
|
||||
loader = torch.utils.data.DataLoader(images, batch_size=64, num_workers=8,
|
||||
shuffle=False) # shuffle=True可以对数据进行随机读取,可以对数据进行洗牌操作(shuffling),打乱数据集内数据分布的顺序
|
||||
train_tranform = transforms.Compose([
|
||||
transforms.RandomResizedCrop(size=224, scale=(0.5, 1), interpolation=transforms.InterpolationMode.BICUBIC),
|
||||
# 随机裁剪 但是保留纵横比
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))
|
||||
])
|
||||
train_images = torchvision.datasets.ImageNet(data_path, split='train',
|
||||
transform=train_tranform)
|
||||
split_by_label_dict = defaultdict(list)
|
||||
# split_by_contexts_dict = defaultdict(list)
|
||||
# for i in range(len(imagenet_classes)):
|
||||
# split_by_contexts_dict[i]=[template.format(imagenet_classes[i]) for template in templates]
|
||||
for i in range(len(train_images.imgs)):
|
||||
split_by_label_dict[train_images.targets[i]].append(train_images.imgs[i])
|
||||
# split_by_contexts_dict[train_images.targets[i]]=[template.format(train_images.classes[train_images.targets[i]]) for template in templates]
|
||||
imgs = []
|
||||
targets = []
|
||||
# contexts=[]
|
||||
for label, items in split_by_label_dict.items():
|
||||
imgs = imgs + random.sample(items, k_shot)
|
||||
targets = targets + [label for i in range(k_shot)]
|
||||
# contexts=contexts+[split_by_context_dict[label] for i in range(k_shot)]
|
||||
|
||||
train_images.imgs = imgs
|
||||
train_images.targets = targets
|
||||
train_images.samples = imgs
|
||||
# train_images.classes= contexts
|
||||
|
||||
# train_loader = torch.utils.data.DataLoader(train_images, batch_size=64, num_workers=8, shuffle=False) # 16个样本
|
||||
train_loader_shuffle = torch.utils.data.DataLoader(train_images, batch_size=256, num_workers=8, shuffle=True)#,drop_last=True)
|
||||
|
||||
return train_loader_shuffle, loader
|
||||
233
data/prepare_data_shot2.py
Normal file
@@ -0,0 +1,233 @@
|
||||
import os
|
||||
import torch
|
||||
import torchvision.transforms as transforms
|
||||
import torchvision.datasets as datasets
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from collections import defaultdict
|
||||
import random
|
||||
|
||||
|
||||
def generate_dataloader(args, preprocess):
|
||||
templates = [
|
||||
"itap of a {}.",
|
||||
"a bad photo of the {}.",
|
||||
"a origami {}.",
|
||||
"a photo of the large {}.",
|
||||
"a {} in a video game.",
|
||||
"art of the {}.",
|
||||
"a photo of the small {}.",
|
||||
]
|
||||
imagenet_classes = ["tench", "goldfish", "great white shark", "tiger shark", "hammerhead shark", "electric ray",
|
||||
"stingray", "rooster", "hen", "ostrich", "brambling", "goldfinch", "house finch", "junco",
|
||||
"indigo bunting", "American robin", "bulbul", "jay", "magpie", "chickadee", "American dipper",
|
||||
"kite (bird of prey)", "bald eagle", "vulture", "great grey owl", "fire salamander",
|
||||
"smooth newt", "newt", "spotted salamander", "axolotl", "American bullfrog", "tree frog",
|
||||
"tailed frog", "loggerhead sea turtle", "leatherback sea turtle", "mud turtle", "terrapin",
|
||||
"box turtle", "banded gecko", "green iguana", "Carolina anole",
|
||||
"desert grassland whiptail lizard", "agama", "frilled-necked lizard", "alligator lizard",
|
||||
"Gila monster", "European green lizard", "chameleon", "Komodo dragon", "Nile crocodile",
|
||||
"American alligator", "triceratops", "worm snake", "ring-necked snake",
|
||||
"eastern hog-nosed snake", "smooth green snake", "kingsnake", "garter snake", "water snake",
|
||||
"vine snake", "night snake", "boa constrictor", "African rock python", "Indian cobra",
|
||||
"green mamba", "sea snake", "Saharan horned viper", "eastern diamondback rattlesnake",
|
||||
"sidewinder rattlesnake", "trilobite", "harvestman", "scorpion", "yellow garden spider",
|
||||
"barn spider", "European garden spider", "southern black widow", "tarantula", "wolf spider",
|
||||
"tick", "centipede", "black grouse", "ptarmigan", "ruffed grouse", "prairie grouse", "peafowl",
|
||||
"quail", "partridge", "african grey parrot", "macaw", "sulphur-crested cockatoo", "lorikeet",
|
||||
"coucal", "bee eater", "hornbill", "hummingbird", "jacamar", "toucan", "duck",
|
||||
"red-breasted merganser", "goose", "black swan", "tusker", "echidna", "platypus", "wallaby",
|
||||
"koala", "wombat", "jellyfish", "sea anemone", "brain coral", "flatworm", "nematode", "conch",
|
||||
"snail", "slug", "sea slug", "chiton", "chambered nautilus", "Dungeness crab", "rock crab",
|
||||
"fiddler crab", "red king crab", "American lobster", "spiny lobster", "crayfish", "hermit crab",
|
||||
"isopod", "white stork", "black stork", "spoonbill", "flamingo", "little blue heron",
|
||||
"great egret", "bittern bird", "crane bird", "limpkin", "common gallinule", "American coot",
|
||||
"bustard", "ruddy turnstone", "dunlin", "common redshank", "dowitcher", "oystercatcher",
|
||||
"pelican", "king penguin", "albatross", "grey whale", "killer whale", "dugong", "sea lion",
|
||||
"Chihuahua", "Japanese Chin", "Maltese", "Pekingese", "Shih Tzu", "King Charles Spaniel",
|
||||
"Papillon", "toy terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset Hound", "Beagle",
|
||||
"Bloodhound", "Bluetick Coonhound", "Black and Tan Coonhound", "Treeing Walker Coonhound",
|
||||
"English foxhound", "Redbone Coonhound", "borzoi", "Irish Wolfhound", "Italian Greyhound",
|
||||
"Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound",
|
||||
"Weimaraner", "Staffordshire Bull Terrier", "American Staffordshire Terrier",
|
||||
"Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier",
|
||||
"Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire Fox Terrier",
|
||||
"Lakeland Terrier", "Sealyham Terrier", "Airedale Terrier", "Cairn Terrier",
|
||||
"Australian Terrier", "Dandie Dinmont Terrier", "Boston Terrier", "Miniature Schnauzer",
|
||||
"Giant Schnauzer", "Standard Schnauzer", "Scottish Terrier", "Tibetan Terrier",
|
||||
"Australian Silky Terrier", "Soft-coated Wheaten Terrier", "West Highland White Terrier",
|
||||
"Lhasa Apso", "Flat-Coated Retriever", "Curly-coated Retriever", "Golden Retriever",
|
||||
"Labrador Retriever", "Chesapeake Bay Retriever", "German Shorthaired Pointer", "Vizsla",
|
||||
"English Setter", "Irish Setter", "Gordon Setter", "Brittany dog", "Clumber Spaniel",
|
||||
"English Springer Spaniel", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel",
|
||||
"Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael dog", "Malinois", "Briard",
|
||||
"Australian Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "collie",
|
||||
"Border Collie", "Bouvier des Flandres dog", "Rottweiler", "German Shepherd Dog", "Dobermann",
|
||||
"Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog",
|
||||
"Appenzeller Sennenhund", "Entlebucher Sennenhund", "Boxer", "Bullmastiff", "Tibetan Mastiff",
|
||||
"French Bulldog", "Great Dane", "St. Bernard", "husky", "Alaskan Malamute", "Siberian Husky",
|
||||
"Dalmatian", "Affenpinscher", "Basenji", "pug", "Leonberger", "Newfoundland dog",
|
||||
"Great Pyrenees dog", "Samoyed", "Pomeranian", "Chow Chow", "Keeshond", "brussels griffon",
|
||||
"Pembroke Welsh Corgi", "Cardigan Welsh Corgi", "Toy Poodle", "Miniature Poodle",
|
||||
"Standard Poodle", "Mexican hairless dog (xoloitzcuintli)", "grey wolf", "Alaskan tundra wolf",
|
||||
"red wolf or maned wolf", "coyote", "dingo", "dhole", "African wild dog", "hyena", "red fox",
|
||||
"kit fox", "Arctic fox", "grey fox", "tabby cat", "tiger cat", "Persian cat", "Siamese cat",
|
||||
"Egyptian Mau", "cougar", "lynx", "leopard", "snow leopard", "jaguar", "lion", "tiger",
|
||||
"cheetah", "brown bear", "American black bear", "polar bear", "sloth bear", "mongoose",
|
||||
"meerkat", "tiger beetle", "ladybug", "ground beetle", "longhorn beetle", "leaf beetle",
|
||||
"dung beetle", "rhinoceros beetle", "weevil", "fly", "bee", "ant", "grasshopper",
|
||||
"cricket insect", "stick insect", "cockroach", "praying mantis", "cicada", "leafhopper",
|
||||
"lacewing", "dragonfly", "damselfly", "red admiral butterfly", "ringlet butterfly",
|
||||
"monarch butterfly", "small white butterfly", "sulphur butterfly", "gossamer-winged butterfly",
|
||||
"starfish", "sea urchin", "sea cucumber", "cottontail rabbit", "hare", "Angora rabbit",
|
||||
"hamster", "porcupine", "fox squirrel", "marmot", "beaver", "guinea pig", "common sorrel horse",
|
||||
"zebra", "pig", "wild boar", "warthog", "hippopotamus", "ox", "water buffalo", "bison",
|
||||
"ram (adult male sheep)", "bighorn sheep", "Alpine ibex", "hartebeest", "impala (antelope)",
|
||||
"gazelle", "arabian camel", "llama", "weasel", "mink", "European polecat",
|
||||
"black-footed ferret", "otter", "skunk", "badger", "armadillo", "three-toed sloth", "orangutan",
|
||||
"gorilla", "chimpanzee", "gibbon", "siamang", "guenon", "patas monkey", "baboon", "macaque",
|
||||
"langur", "black-and-white colobus", "proboscis monkey", "marmoset", "white-headed capuchin",
|
||||
"howler monkey", "titi monkey", "Geoffroy's spider monkey", "common squirrel monkey",
|
||||
"ring-tailed lemur", "indri", "Asian elephant", "African bush elephant", "red panda",
|
||||
"giant panda", "snoek fish", "eel", "silver salmon", "rock beauty fish", "clownfish",
|
||||
"sturgeon", "gar fish", "lionfish", "pufferfish", "abacus", "abaya", "academic gown",
|
||||
"accordion", "acoustic guitar", "aircraft carrier", "airliner", "airship", "altar", "ambulance",
|
||||
"amphibious vehicle", "analog clock", "apiary", "apron", "trash can", "assault rifle",
|
||||
"backpack", "bakery", "balance beam", "balloon", "ballpoint pen", "Band-Aid", "banjo",
|
||||
"baluster / handrail", "barbell", "barber chair", "barbershop", "barn", "barometer", "barrel",
|
||||
"wheelbarrow", "baseball", "basketball", "bassinet", "bassoon", "swimming cap", "bath towel",
|
||||
"bathtub", "station wagon", "lighthouse", "beaker", "military hat (bearskin or shako)",
|
||||
"beer bottle", "beer glass", "bell tower", "baby bib", "tandem bicycle", "bikini",
|
||||
"ring binder", "binoculars", "birdhouse", "boathouse", "bobsleigh", "bolo tie", "poke bonnet",
|
||||
"bookcase", "bookstore", "bottle cap", "hunting bow", "bow tie", "brass memorial plaque", "bra",
|
||||
"breakwater", "breastplate", "broom", "bucket", "buckle", "bulletproof vest",
|
||||
"high-speed train", "butcher shop", "taxicab", "cauldron", "candle", "cannon", "canoe",
|
||||
"can opener", "cardigan", "car mirror", "carousel", "tool kit", "cardboard box / carton",
|
||||
"car wheel", "automated teller machine", "cassette", "cassette player", "castle", "catamaran",
|
||||
"CD player", "cello", "mobile phone", "chain", "chain-link fence", "chain mail", "chainsaw",
|
||||
"storage chest", "chiffonier", "bell or wind chime", "china cabinet", "Christmas stocking",
|
||||
"church", "movie theater", "cleaver", "cliff dwelling", "cloak", "clogs", "cocktail shaker",
|
||||
"coffee mug", "coffeemaker", "spiral or coil", "combination lock", "computer keyboard",
|
||||
"candy store", "container ship", "convertible", "corkscrew", "cornet", "cowboy boot",
|
||||
"cowboy hat", "cradle", "construction crane", "crash helmet", "crate", "infant bed",
|
||||
"Crock Pot", "croquet ball", "crutch", "cuirass", "dam", "desk", "desktop computer",
|
||||
"rotary dial telephone", "diaper", "digital clock", "digital watch", "dining table",
|
||||
"dishcloth", "dishwasher", "disc brake", "dock", "dog sled", "dome", "doormat", "drilling rig",
|
||||
"drum", "drumstick", "dumbbell", "Dutch oven", "electric fan", "electric guitar",
|
||||
"electric locomotive", "entertainment center", "envelope", "espresso machine", "face powder",
|
||||
"feather boa", "filing cabinet", "fireboat", "fire truck", "fire screen", "flagpole", "flute",
|
||||
"folding chair", "football helmet", "forklift", "fountain", "fountain pen", "four-poster bed",
|
||||
"freight car", "French horn", "frying pan", "fur coat", "garbage truck",
|
||||
"gas mask or respirator", "gas pump", "goblet", "go-kart", "golf ball", "golf cart", "gondola",
|
||||
"gong", "gown", "grand piano", "greenhouse", "radiator grille", "grocery store", "guillotine",
|
||||
"hair clip", "hair spray", "half-track", "hammer", "hamper", "hair dryer", "hand-held computer",
|
||||
"handkerchief", "hard disk drive", "harmonica", "harp", "combine harvester", "hatchet",
|
||||
"holster", "home theater", "honeycomb", "hook", "hoop skirt", "gymnastic horizontal bar",
|
||||
"horse-drawn vehicle", "hourglass", "iPod", "clothes iron", "carved pumpkin", "jeans", "jeep",
|
||||
"T-shirt", "jigsaw puzzle", "rickshaw", "joystick", "kimono", "knee pad", "knot", "lab coat",
|
||||
"ladle", "lampshade", "laptop computer", "lawn mower", "lens cap", "letter opener", "library",
|
||||
"lifeboat", "lighter", "limousine", "ocean liner", "lipstick", "slip-on shoe", "lotion",
|
||||
"music speaker", "loupe magnifying glass", "sawmill", "magnetic compass", "messenger bag",
|
||||
"mailbox", "tights", "one-piece bathing suit", "manhole cover", "maraca", "marimba", "mask",
|
||||
"matchstick", "maypole", "maze", "measuring cup", "medicine cabinet", "megalith", "microphone",
|
||||
"microwave oven", "military uniform", "milk can", "minibus", "miniskirt", "minivan", "missile",
|
||||
"mitten", "mixing bowl", "mobile home", "ford model t", "modem", "monastery", "monitor",
|
||||
"moped", "mortar and pestle", "graduation cap", "mosque", "mosquito net", "vespa",
|
||||
"mountain bike", "tent", "computer mouse", "mousetrap", "moving van", "muzzle", "metal nail",
|
||||
"neck brace", "necklace", "baby pacifier", "notebook computer", "obelisk", "oboe", "ocarina",
|
||||
"odometer", "oil filter", "pipe organ", "oscilloscope", "overskirt", "bullock cart",
|
||||
"oxygen mask", "product packet / packaging", "paddle", "paddle wheel", "padlock", "paintbrush",
|
||||
"pajamas", "palace", "pan flute", "paper towel", "parachute", "parallel bars", "park bench",
|
||||
"parking meter", "railroad car", "patio", "payphone", "pedestal", "pencil case",
|
||||
"pencil sharpener", "perfume", "Petri dish", "photocopier", "plectrum", "Pickelhaube",
|
||||
"picket fence", "pickup truck", "pier", "piggy bank", "pill bottle", "pillow", "ping-pong ball",
|
||||
"pinwheel", "pirate ship", "drink pitcher", "block plane", "planetarium", "plastic bag",
|
||||
"plate rack", "farm plow", "plunger", "Polaroid camera", "pole", "police van", "poncho",
|
||||
"pool table", "soda bottle", "plant pot", "potter's wheel", "power drill", "prayer rug",
|
||||
"printer", "prison", "missile", "projector", "hockey puck", "punching bag", "purse", "quill",
|
||||
"quilt", "race car", "racket", "radiator", "radio", "radio telescope", "rain barrel",
|
||||
"recreational vehicle", "fishing casting reel", "reflex camera", "refrigerator",
|
||||
"remote control", "restaurant", "revolver", "rifle", "rocking chair", "rotisserie", "eraser",
|
||||
"rugby ball", "ruler measuring stick", "sneaker", "safe", "safety pin", "salt shaker", "sandal",
|
||||
"sarong", "saxophone", "scabbard", "weighing scale", "school bus", "schooner", "scoreboard",
|
||||
"CRT monitor", "screw", "screwdriver", "seat belt", "sewing machine", "shield", "shoe store",
|
||||
"shoji screen / room divider", "shopping basket", "shopping cart", "shovel", "shower cap",
|
||||
"shower curtain", "ski", "balaclava ski mask", "sleeping bag", "slide rule", "sliding door",
|
||||
"slot machine", "snorkel", "snowmobile", "snowplow", "soap dispenser", "soccer ball", "sock",
|
||||
"solar thermal collector", "sombrero", "soup bowl", "keyboard space bar", "space heater",
|
||||
"space shuttle", "spatula", "motorboat", "spider web", "spindle", "sports car", "spotlight",
|
||||
"stage", "steam locomotive", "through arch bridge", "steel drum", "stethoscope", "scarf",
|
||||
"stone wall", "stopwatch", "stove", "strainer", "tram", "stretcher", "couch", "stupa",
|
||||
"submarine", "suit", "sundial", "sunglasses", "sunglasses", "sunscreen", "suspension bridge",
|
||||
"mop", "sweatshirt", "swim trunks / shorts", "swing", "electrical switch", "syringe",
|
||||
"table lamp", "tank", "tape player", "teapot", "teddy bear", "television", "tennis ball",
|
||||
"thatched roof", "front curtain", "thimble", "threshing machine", "throne", "tile roof",
|
||||
"toaster", "tobacco shop", "toilet seat", "torch", "totem pole", "tow truck", "toy store",
|
||||
"tractor", "semi-trailer truck", "tray", "trench coat", "tricycle", "trimaran", "tripod",
|
||||
"triumphal arch", "trolleybus", "trombone", "hot tub", "turnstile", "typewriter keyboard",
|
||||
"umbrella", "unicycle", "upright piano", "vacuum cleaner", "vase", "vaulted or arched ceiling",
|
||||
"velvet fabric", "vending machine", "vestment", "viaduct", "violin", "volleyball",
|
||||
"waffle iron", "wall clock", "wallet", "wardrobe", "military aircraft", "sink",
|
||||
"washing machine", "water bottle", "water jug", "water tower", "whiskey jug", "whistle",
|
||||
"hair wig", "window screen", "window shade", "Windsor tie", "wine bottle", "airplane wing",
|
||||
"wok", "wooden spoon", "wool", "split-rail fence", "shipwreck", "sailboat", "yurt", "website",
|
||||
"comic book", "crossword", "traffic or street sign", "traffic light", "dust jacket", "menu",
|
||||
"plate", "guacamole", "consomme", "hot pot", "trifle", "ice cream", "popsicle", "baguette",
|
||||
"bagel", "pretzel", "cheeseburger", "hot dog", "mashed potatoes", "cabbage", "broccoli",
|
||||
"cauliflower", "zucchini", "spaghetti squash", "acorn squash", "butternut squash", "cucumber",
|
||||
"artichoke", "bell pepper", "cardoon", "mushroom", "Granny Smith apple", "strawberry", "orange",
|
||||
"lemon", "fig", "pineapple", "banana", "jackfruit", "cherimoya (custard apple)", "pomegranate",
|
||||
"hay", "carbonara", "chocolate syrup", "dough", "meatloaf", "pizza", "pot pie", "burrito",
|
||||
"red wine", "espresso", "tea cup", "eggnog", "mountain", "bubble", "cliff", "coral reef",
|
||||
"geyser", "lakeshore", "promontory", "sandbar", "beach", "valley", "volcano", "baseball player",
|
||||
"bridegroom", "scuba diver", "rapeseed", "daisy", "yellow lady's slipper", "corn", "acorn",
|
||||
"rose hip", "horse chestnut seed", "coral fungus", "agaric", "gyromitra", "stinkhorn mushroom",
|
||||
"earth star fungus", "hen of the woods mushroom", "bolete", "corn cob", "toilet paper"]
|
||||
|
||||
random.seed(1)
|
||||
k_shot = 2
|
||||
# Data loading code
|
||||
data_path = args.data_path_source
|
||||
traindir_source = os.path.join(args.data_path_source, args.src)
|
||||
traindir_target = os.path.join(args.data_path_source_t, args.src_t)
|
||||
valdir = os.path.join(args.data_path_target, args.tar)
|
||||
if not os.path.isdir(traindir_source):
|
||||
# split_train_test_images(args.data_path)
|
||||
raise ValueError('Null path of source train data!!!')
|
||||
|
||||
images = torchvision.datasets.ImageNet(data_path, split='val', transform=preprocess)
|
||||
loader = torch.utils.data.DataLoader(images, batch_size=64, num_workers=0,
|
||||
shuffle=False) # shuffle=True可以对数据进行随机读取,可以对数据进行洗牌操作(shuffling),打乱数据集内数据分布的顺序
|
||||
train_tranform = transforms.Compose([
|
||||
transforms.RandomResizedCrop(size=224, scale=(0.5, 1), interpolation=transforms.InterpolationMode.BICUBIC),
|
||||
# 随机裁剪 但是保留纵横比
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))
|
||||
])
|
||||
train_images = torchvision.datasets.ImageNet(data_path, split='train',
|
||||
transform=train_tranform)
|
||||
split_by_label_dict = defaultdict(list)
|
||||
# split_by_contexts_dict = defaultdict(list)
|
||||
# for i in range(len(imagenet_classes)):
|
||||
# split_by_contexts_dict[i]=[template.format(imagenet_classes[i]) for template in templates]
|
||||
for i in range(len(train_images.imgs)):
|
||||
split_by_label_dict[train_images.targets[i]].append(train_images.imgs[i])
|
||||
# split_by_contexts_dict[train_images.targets[i]]=[template.format(train_images.classes[train_images.targets[i]]) for template in templates]
|
||||
imgs = []
|
||||
targets = []
|
||||
# contexts=[]
|
||||
for label, items in split_by_label_dict.items():
|
||||
imgs = imgs + random.sample(items, k_shot)
|
||||
targets = targets + [label for i in range(k_shot)]
|
||||
# contexts=contexts+[split_by_context_dict[label] for i in range(k_shot)]
|
||||
|
||||
train_images.imgs = imgs
|
||||
train_images.targets = targets
|
||||
train_images.samples = imgs
|
||||
# train_images.classes= contexts
|
||||
|
||||
# train_loader = torch.utils.data.DataLoader(train_images, batch_size=64, num_workers=8, shuffle=False) # 16个样本
|
||||
train_loader_shuffle = torch.utils.data.DataLoader(train_images, batch_size=256, num_workers=0, shuffle=True)#,drop_last=True)
|
||||
|
||||
return train_loader_shuffle, loader
|
||||
233
data/prepare_data_shot4.py
Normal file
@@ -0,0 +1,233 @@
|
||||
import os
|
||||
import torch
|
||||
import torchvision.transforms as transforms
|
||||
import torchvision.datasets as datasets
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from collections import defaultdict
|
||||
import random
|
||||
|
||||
|
||||
def generate_dataloader(args, preprocess):
|
||||
templates = [
|
||||
"itap of a {}.",
|
||||
"a bad photo of the {}.",
|
||||
"a origami {}.",
|
||||
"a photo of the large {}.",
|
||||
"a {} in a video game.",
|
||||
"art of the {}.",
|
||||
"a photo of the small {}.",
|
||||
]
|
||||
imagenet_classes = ["tench", "goldfish", "great white shark", "tiger shark", "hammerhead shark", "electric ray",
|
||||
"stingray", "rooster", "hen", "ostrich", "brambling", "goldfinch", "house finch", "junco",
|
||||
"indigo bunting", "American robin", "bulbul", "jay", "magpie", "chickadee", "American dipper",
|
||||
"kite (bird of prey)", "bald eagle", "vulture", "great grey owl", "fire salamander",
|
||||
"smooth newt", "newt", "spotted salamander", "axolotl", "American bullfrog", "tree frog",
|
||||
"tailed frog", "loggerhead sea turtle", "leatherback sea turtle", "mud turtle", "terrapin",
|
||||
"box turtle", "banded gecko", "green iguana", "Carolina anole",
|
||||
"desert grassland whiptail lizard", "agama", "frilled-necked lizard", "alligator lizard",
|
||||
"Gila monster", "European green lizard", "chameleon", "Komodo dragon", "Nile crocodile",
|
||||
"American alligator", "triceratops", "worm snake", "ring-necked snake",
|
||||
"eastern hog-nosed snake", "smooth green snake", "kingsnake", "garter snake", "water snake",
|
||||
"vine snake", "night snake", "boa constrictor", "African rock python", "Indian cobra",
|
||||
"green mamba", "sea snake", "Saharan horned viper", "eastern diamondback rattlesnake",
|
||||
"sidewinder rattlesnake", "trilobite", "harvestman", "scorpion", "yellow garden spider",
|
||||
"barn spider", "European garden spider", "southern black widow", "tarantula", "wolf spider",
|
||||
"tick", "centipede", "black grouse", "ptarmigan", "ruffed grouse", "prairie grouse", "peafowl",
|
||||
"quail", "partridge", "african grey parrot", "macaw", "sulphur-crested cockatoo", "lorikeet",
|
||||
"coucal", "bee eater", "hornbill", "hummingbird", "jacamar", "toucan", "duck",
|
||||
"red-breasted merganser", "goose", "black swan", "tusker", "echidna", "platypus", "wallaby",
|
||||
"koala", "wombat", "jellyfish", "sea anemone", "brain coral", "flatworm", "nematode", "conch",
|
||||
"snail", "slug", "sea slug", "chiton", "chambered nautilus", "Dungeness crab", "rock crab",
|
||||
"fiddler crab", "red king crab", "American lobster", "spiny lobster", "crayfish", "hermit crab",
|
||||
"isopod", "white stork", "black stork", "spoonbill", "flamingo", "little blue heron",
|
||||
"great egret", "bittern bird", "crane bird", "limpkin", "common gallinule", "American coot",
|
||||
"bustard", "ruddy turnstone", "dunlin", "common redshank", "dowitcher", "oystercatcher",
|
||||
"pelican", "king penguin", "albatross", "grey whale", "killer whale", "dugong", "sea lion",
|
||||
"Chihuahua", "Japanese Chin", "Maltese", "Pekingese", "Shih Tzu", "King Charles Spaniel",
|
||||
"Papillon", "toy terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset Hound", "Beagle",
|
||||
"Bloodhound", "Bluetick Coonhound", "Black and Tan Coonhound", "Treeing Walker Coonhound",
|
||||
"English foxhound", "Redbone Coonhound", "borzoi", "Irish Wolfhound", "Italian Greyhound",
|
||||
"Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound",
|
||||
"Weimaraner", "Staffordshire Bull Terrier", "American Staffordshire Terrier",
|
||||
"Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier",
|
||||
"Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire Fox Terrier",
|
||||
"Lakeland Terrier", "Sealyham Terrier", "Airedale Terrier", "Cairn Terrier",
|
||||
"Australian Terrier", "Dandie Dinmont Terrier", "Boston Terrier", "Miniature Schnauzer",
|
||||
"Giant Schnauzer", "Standard Schnauzer", "Scottish Terrier", "Tibetan Terrier",
|
||||
"Australian Silky Terrier", "Soft-coated Wheaten Terrier", "West Highland White Terrier",
|
||||
"Lhasa Apso", "Flat-Coated Retriever", "Curly-coated Retriever", "Golden Retriever",
|
||||
"Labrador Retriever", "Chesapeake Bay Retriever", "German Shorthaired Pointer", "Vizsla",
|
||||
"English Setter", "Irish Setter", "Gordon Setter", "Brittany dog", "Clumber Spaniel",
|
||||
"English Springer Spaniel", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel",
|
||||
"Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael dog", "Malinois", "Briard",
|
||||
"Australian Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "collie",
|
||||
"Border Collie", "Bouvier des Flandres dog", "Rottweiler", "German Shepherd Dog", "Dobermann",
|
||||
"Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog",
|
||||
"Appenzeller Sennenhund", "Entlebucher Sennenhund", "Boxer", "Bullmastiff", "Tibetan Mastiff",
|
||||
"French Bulldog", "Great Dane", "St. Bernard", "husky", "Alaskan Malamute", "Siberian Husky",
|
||||
"Dalmatian", "Affenpinscher", "Basenji", "pug", "Leonberger", "Newfoundland dog",
|
||||
"Great Pyrenees dog", "Samoyed", "Pomeranian", "Chow Chow", "Keeshond", "brussels griffon",
|
||||
"Pembroke Welsh Corgi", "Cardigan Welsh Corgi", "Toy Poodle", "Miniature Poodle",
|
||||
"Standard Poodle", "Mexican hairless dog (xoloitzcuintli)", "grey wolf", "Alaskan tundra wolf",
|
||||
"red wolf or maned wolf", "coyote", "dingo", "dhole", "African wild dog", "hyena", "red fox",
|
||||
"kit fox", "Arctic fox", "grey fox", "tabby cat", "tiger cat", "Persian cat", "Siamese cat",
|
||||
"Egyptian Mau", "cougar", "lynx", "leopard", "snow leopard", "jaguar", "lion", "tiger",
|
||||
"cheetah", "brown bear", "American black bear", "polar bear", "sloth bear", "mongoose",
|
||||
"meerkat", "tiger beetle", "ladybug", "ground beetle", "longhorn beetle", "leaf beetle",
|
||||
"dung beetle", "rhinoceros beetle", "weevil", "fly", "bee", "ant", "grasshopper",
|
||||
"cricket insect", "stick insect", "cockroach", "praying mantis", "cicada", "leafhopper",
|
||||
"lacewing", "dragonfly", "damselfly", "red admiral butterfly", "ringlet butterfly",
|
||||
"monarch butterfly", "small white butterfly", "sulphur butterfly", "gossamer-winged butterfly",
|
||||
"starfish", "sea urchin", "sea cucumber", "cottontail rabbit", "hare", "Angora rabbit",
|
||||
"hamster", "porcupine", "fox squirrel", "marmot", "beaver", "guinea pig", "common sorrel horse",
|
||||
"zebra", "pig", "wild boar", "warthog", "hippopotamus", "ox", "water buffalo", "bison",
|
||||
"ram (adult male sheep)", "bighorn sheep", "Alpine ibex", "hartebeest", "impala (antelope)",
|
||||
"gazelle", "arabian camel", "llama", "weasel", "mink", "European polecat",
|
||||
"black-footed ferret", "otter", "skunk", "badger", "armadillo", "three-toed sloth", "orangutan",
|
||||
"gorilla", "chimpanzee", "gibbon", "siamang", "guenon", "patas monkey", "baboon", "macaque",
|
||||
"langur", "black-and-white colobus", "proboscis monkey", "marmoset", "white-headed capuchin",
|
||||
"howler monkey", "titi monkey", "Geoffroy's spider monkey", "common squirrel monkey",
|
||||
"ring-tailed lemur", "indri", "Asian elephant", "African bush elephant", "red panda",
|
||||
"giant panda", "snoek fish", "eel", "silver salmon", "rock beauty fish", "clownfish",
|
||||
"sturgeon", "gar fish", "lionfish", "pufferfish", "abacus", "abaya", "academic gown",
|
||||
"accordion", "acoustic guitar", "aircraft carrier", "airliner", "airship", "altar", "ambulance",
|
||||
"amphibious vehicle", "analog clock", "apiary", "apron", "trash can", "assault rifle",
|
||||
"backpack", "bakery", "balance beam", "balloon", "ballpoint pen", "Band-Aid", "banjo",
|
||||
"baluster / handrail", "barbell", "barber chair", "barbershop", "barn", "barometer", "barrel",
|
||||
"wheelbarrow", "baseball", "basketball", "bassinet", "bassoon", "swimming cap", "bath towel",
|
||||
"bathtub", "station wagon", "lighthouse", "beaker", "military hat (bearskin or shako)",
|
||||
"beer bottle", "beer glass", "bell tower", "baby bib", "tandem bicycle", "bikini",
|
||||
"ring binder", "binoculars", "birdhouse", "boathouse", "bobsleigh", "bolo tie", "poke bonnet",
|
||||
"bookcase", "bookstore", "bottle cap", "hunting bow", "bow tie", "brass memorial plaque", "bra",
|
||||
"breakwater", "breastplate", "broom", "bucket", "buckle", "bulletproof vest",
|
||||
"high-speed train", "butcher shop", "taxicab", "cauldron", "candle", "cannon", "canoe",
|
||||
"can opener", "cardigan", "car mirror", "carousel", "tool kit", "cardboard box / carton",
|
||||
"car wheel", "automated teller machine", "cassette", "cassette player", "castle", "catamaran",
|
||||
"CD player", "cello", "mobile phone", "chain", "chain-link fence", "chain mail", "chainsaw",
|
||||
"storage chest", "chiffonier", "bell or wind chime", "china cabinet", "Christmas stocking",
|
||||
"church", "movie theater", "cleaver", "cliff dwelling", "cloak", "clogs", "cocktail shaker",
|
||||
"coffee mug", "coffeemaker", "spiral or coil", "combination lock", "computer keyboard",
|
||||
"candy store", "container ship", "convertible", "corkscrew", "cornet", "cowboy boot",
|
||||
"cowboy hat", "cradle", "construction crane", "crash helmet", "crate", "infant bed",
|
||||
"Crock Pot", "croquet ball", "crutch", "cuirass", "dam", "desk", "desktop computer",
|
||||
"rotary dial telephone", "diaper", "digital clock", "digital watch", "dining table",
|
||||
"dishcloth", "dishwasher", "disc brake", "dock", "dog sled", "dome", "doormat", "drilling rig",
|
||||
"drum", "drumstick", "dumbbell", "Dutch oven", "electric fan", "electric guitar",
|
||||
"electric locomotive", "entertainment center", "envelope", "espresso machine", "face powder",
|
||||
"feather boa", "filing cabinet", "fireboat", "fire truck", "fire screen", "flagpole", "flute",
|
||||
"folding chair", "football helmet", "forklift", "fountain", "fountain pen", "four-poster bed",
|
||||
"freight car", "French horn", "frying pan", "fur coat", "garbage truck",
|
||||
"gas mask or respirator", "gas pump", "goblet", "go-kart", "golf ball", "golf cart", "gondola",
|
||||
"gong", "gown", "grand piano", "greenhouse", "radiator grille", "grocery store", "guillotine",
|
||||
"hair clip", "hair spray", "half-track", "hammer", "hamper", "hair dryer", "hand-held computer",
|
||||
"handkerchief", "hard disk drive", "harmonica", "harp", "combine harvester", "hatchet",
|
||||
"holster", "home theater", "honeycomb", "hook", "hoop skirt", "gymnastic horizontal bar",
|
||||
"horse-drawn vehicle", "hourglass", "iPod", "clothes iron", "carved pumpkin", "jeans", "jeep",
|
||||
"T-shirt", "jigsaw puzzle", "rickshaw", "joystick", "kimono", "knee pad", "knot", "lab coat",
|
||||
"ladle", "lampshade", "laptop computer", "lawn mower", "lens cap", "letter opener", "library",
|
||||
"lifeboat", "lighter", "limousine", "ocean liner", "lipstick", "slip-on shoe", "lotion",
|
||||
"music speaker", "loupe magnifying glass", "sawmill", "magnetic compass", "messenger bag",
|
||||
"mailbox", "tights", "one-piece bathing suit", "manhole cover", "maraca", "marimba", "mask",
|
||||
"matchstick", "maypole", "maze", "measuring cup", "medicine cabinet", "megalith", "microphone",
|
||||
"microwave oven", "military uniform", "milk can", "minibus", "miniskirt", "minivan", "missile",
|
||||
"mitten", "mixing bowl", "mobile home", "ford model t", "modem", "monastery", "monitor",
|
||||
"moped", "mortar and pestle", "graduation cap", "mosque", "mosquito net", "vespa",
|
||||
"mountain bike", "tent", "computer mouse", "mousetrap", "moving van", "muzzle", "metal nail",
|
||||
"neck brace", "necklace", "baby pacifier", "notebook computer", "obelisk", "oboe", "ocarina",
|
||||
"odometer", "oil filter", "pipe organ", "oscilloscope", "overskirt", "bullock cart",
|
||||
"oxygen mask", "product packet / packaging", "paddle", "paddle wheel", "padlock", "paintbrush",
|
||||
"pajamas", "palace", "pan flute", "paper towel", "parachute", "parallel bars", "park bench",
|
||||
"parking meter", "railroad car", "patio", "payphone", "pedestal", "pencil case",
|
||||
"pencil sharpener", "perfume", "Petri dish", "photocopier", "plectrum", "Pickelhaube",
|
||||
"picket fence", "pickup truck", "pier", "piggy bank", "pill bottle", "pillow", "ping-pong ball",
|
||||
"pinwheel", "pirate ship", "drink pitcher", "block plane", "planetarium", "plastic bag",
|
||||
"plate rack", "farm plow", "plunger", "Polaroid camera", "pole", "police van", "poncho",
|
||||
"pool table", "soda bottle", "plant pot", "potter's wheel", "power drill", "prayer rug",
|
||||
"printer", "prison", "missile", "projector", "hockey puck", "punching bag", "purse", "quill",
|
||||
"quilt", "race car", "racket", "radiator", "radio", "radio telescope", "rain barrel",
|
||||
"recreational vehicle", "fishing casting reel", "reflex camera", "refrigerator",
|
||||
"remote control", "restaurant", "revolver", "rifle", "rocking chair", "rotisserie", "eraser",
|
||||
"rugby ball", "ruler measuring stick", "sneaker", "safe", "safety pin", "salt shaker", "sandal",
|
||||
"sarong", "saxophone", "scabbard", "weighing scale", "school bus", "schooner", "scoreboard",
|
||||
"CRT monitor", "screw", "screwdriver", "seat belt", "sewing machine", "shield", "shoe store",
|
||||
"shoji screen / room divider", "shopping basket", "shopping cart", "shovel", "shower cap",
|
||||
"shower curtain", "ski", "balaclava ski mask", "sleeping bag", "slide rule", "sliding door",
|
||||
"slot machine", "snorkel", "snowmobile", "snowplow", "soap dispenser", "soccer ball", "sock",
|
||||
"solar thermal collector", "sombrero", "soup bowl", "keyboard space bar", "space heater",
|
||||
"space shuttle", "spatula", "motorboat", "spider web", "spindle", "sports car", "spotlight",
|
||||
"stage", "steam locomotive", "through arch bridge", "steel drum", "stethoscope", "scarf",
|
||||
"stone wall", "stopwatch", "stove", "strainer", "tram", "stretcher", "couch", "stupa",
|
||||
"submarine", "suit", "sundial", "sunglasses", "sunglasses", "sunscreen", "suspension bridge",
|
||||
"mop", "sweatshirt", "swim trunks / shorts", "swing", "electrical switch", "syringe",
|
||||
"table lamp", "tank", "tape player", "teapot", "teddy bear", "television", "tennis ball",
|
||||
"thatched roof", "front curtain", "thimble", "threshing machine", "throne", "tile roof",
|
||||
"toaster", "tobacco shop", "toilet seat", "torch", "totem pole", "tow truck", "toy store",
|
||||
"tractor", "semi-trailer truck", "tray", "trench coat", "tricycle", "trimaran", "tripod",
|
||||
"triumphal arch", "trolleybus", "trombone", "hot tub", "turnstile", "typewriter keyboard",
|
||||
"umbrella", "unicycle", "upright piano", "vacuum cleaner", "vase", "vaulted or arched ceiling",
|
||||
"velvet fabric", "vending machine", "vestment", "viaduct", "violin", "volleyball",
|
||||
"waffle iron", "wall clock", "wallet", "wardrobe", "military aircraft", "sink",
|
||||
"washing machine", "water bottle", "water jug", "water tower", "whiskey jug", "whistle",
|
||||
"hair wig", "window screen", "window shade", "Windsor tie", "wine bottle", "airplane wing",
|
||||
"wok", "wooden spoon", "wool", "split-rail fence", "shipwreck", "sailboat", "yurt", "website",
|
||||
"comic book", "crossword", "traffic or street sign", "traffic light", "dust jacket", "menu",
|
||||
"plate", "guacamole", "consomme", "hot pot", "trifle", "ice cream", "popsicle", "baguette",
|
||||
"bagel", "pretzel", "cheeseburger", "hot dog", "mashed potatoes", "cabbage", "broccoli",
|
||||
"cauliflower", "zucchini", "spaghetti squash", "acorn squash", "butternut squash", "cucumber",
|
||||
"artichoke", "bell pepper", "cardoon", "mushroom", "Granny Smith apple", "strawberry", "orange",
|
||||
"lemon", "fig", "pineapple", "banana", "jackfruit", "cherimoya (custard apple)", "pomegranate",
|
||||
"hay", "carbonara", "chocolate syrup", "dough", "meatloaf", "pizza", "pot pie", "burrito",
|
||||
"red wine", "espresso", "tea cup", "eggnog", "mountain", "bubble", "cliff", "coral reef",
|
||||
"geyser", "lakeshore", "promontory", "sandbar", "beach", "valley", "volcano", "baseball player",
|
||||
"bridegroom", "scuba diver", "rapeseed", "daisy", "yellow lady's slipper", "corn", "acorn",
|
||||
"rose hip", "horse chestnut seed", "coral fungus", "agaric", "gyromitra", "stinkhorn mushroom",
|
||||
"earth star fungus", "hen of the woods mushroom", "bolete", "corn cob", "toilet paper"]
|
||||
|
||||
random.seed(1)
|
||||
k_shot = 4
|
||||
# Data loading code
|
||||
data_path = args.data_path_source
|
||||
traindir_source = os.path.join(args.data_path_source, args.src)
|
||||
traindir_target = os.path.join(args.data_path_source_t, args.src_t)
|
||||
valdir = os.path.join(args.data_path_target, args.tar)
|
||||
if not os.path.isdir(traindir_source):
|
||||
# split_train_test_images(args.data_path)
|
||||
raise ValueError('Null path of source train data!!!')
|
||||
|
||||
images = torchvision.datasets.ImageNet(data_path, split='val', transform=preprocess)
|
||||
loader = torch.utils.data.DataLoader(images, batch_size=64, num_workers=0,
|
||||
shuffle=False) # shuffle=True可以对数据进行随机读取,可以对数据进行洗牌操作(shuffling),打乱数据集内数据分布的顺序
|
||||
train_tranform = transforms.Compose([
|
||||
transforms.RandomResizedCrop(size=224, scale=(0.5, 1), interpolation=transforms.InterpolationMode.BICUBIC),
|
||||
# 随机裁剪 但是保留纵横比
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))
|
||||
])
|
||||
train_images = torchvision.datasets.ImageNet(data_path, split='train',
|
||||
transform=train_tranform)
|
||||
split_by_label_dict = defaultdict(list)
|
||||
# split_by_contexts_dict = defaultdict(list)
|
||||
# for i in range(len(imagenet_classes)):
|
||||
# split_by_contexts_dict[i]=[template.format(imagenet_classes[i]) for template in templates]
|
||||
for i in range(len(train_images.imgs)):
|
||||
split_by_label_dict[train_images.targets[i]].append(train_images.imgs[i])
|
||||
# split_by_contexts_dict[train_images.targets[i]]=[template.format(train_images.classes[train_images.targets[i]]) for template in templates]
|
||||
imgs = []
|
||||
targets = []
|
||||
# contexts=[]
|
||||
for label, items in split_by_label_dict.items():
|
||||
imgs = imgs + random.sample(items, k_shot)
|
||||
targets = targets + [label for i in range(k_shot)]
|
||||
# contexts=contexts+[split_by_context_dict[label] for i in range(k_shot)]
|
||||
|
||||
train_images.imgs = imgs
|
||||
train_images.targets = targets
|
||||
train_images.samples = imgs
|
||||
# train_images.classes= contexts
|
||||
|
||||
# train_loader = torch.utils.data.DataLoader(train_images, batch_size=64, num_workers=8, shuffle=False) # 16个样本
|
||||
train_loader_shuffle = torch.utils.data.DataLoader(train_images, batch_size=256, num_workers=0, shuffle=True)#,drop_last=True)
|
||||
|
||||
return train_loader_shuffle, loader
|
||||
233
data/prepare_data_shot8.py
Normal file
@@ -0,0 +1,233 @@
|
||||
import os
|
||||
import torch
|
||||
import torchvision.transforms as transforms
|
||||
import torchvision.datasets as datasets
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from collections import defaultdict
|
||||
import random
|
||||
|
||||
|
||||
def generate_dataloader(args, preprocess):
|
||||
templates = [
|
||||
"itap of a {}.",
|
||||
"a bad photo of the {}.",
|
||||
"a origami {}.",
|
||||
"a photo of the large {}.",
|
||||
"a {} in a video game.",
|
||||
"art of the {}.",
|
||||
"a photo of the small {}.",
|
||||
]
|
||||
imagenet_classes = ["tench", "goldfish", "great white shark", "tiger shark", "hammerhead shark", "electric ray",
|
||||
"stingray", "rooster", "hen", "ostrich", "brambling", "goldfinch", "house finch", "junco",
|
||||
"indigo bunting", "American robin", "bulbul", "jay", "magpie", "chickadee", "American dipper",
|
||||
"kite (bird of prey)", "bald eagle", "vulture", "great grey owl", "fire salamander",
|
||||
"smooth newt", "newt", "spotted salamander", "axolotl", "American bullfrog", "tree frog",
|
||||
"tailed frog", "loggerhead sea turtle", "leatherback sea turtle", "mud turtle", "terrapin",
|
||||
"box turtle", "banded gecko", "green iguana", "Carolina anole",
|
||||
"desert grassland whiptail lizard", "agama", "frilled-necked lizard", "alligator lizard",
|
||||
"Gila monster", "European green lizard", "chameleon", "Komodo dragon", "Nile crocodile",
|
||||
"American alligator", "triceratops", "worm snake", "ring-necked snake",
|
||||
"eastern hog-nosed snake", "smooth green snake", "kingsnake", "garter snake", "water snake",
|
||||
"vine snake", "night snake", "boa constrictor", "African rock python", "Indian cobra",
|
||||
"green mamba", "sea snake", "Saharan horned viper", "eastern diamondback rattlesnake",
|
||||
"sidewinder rattlesnake", "trilobite", "harvestman", "scorpion", "yellow garden spider",
|
||||
"barn spider", "European garden spider", "southern black widow", "tarantula", "wolf spider",
|
||||
"tick", "centipede", "black grouse", "ptarmigan", "ruffed grouse", "prairie grouse", "peafowl",
|
||||
"quail", "partridge", "african grey parrot", "macaw", "sulphur-crested cockatoo", "lorikeet",
|
||||
"coucal", "bee eater", "hornbill", "hummingbird", "jacamar", "toucan", "duck",
|
||||
"red-breasted merganser", "goose", "black swan", "tusker", "echidna", "platypus", "wallaby",
|
||||
"koala", "wombat", "jellyfish", "sea anemone", "brain coral", "flatworm", "nematode", "conch",
|
||||
"snail", "slug", "sea slug", "chiton", "chambered nautilus", "Dungeness crab", "rock crab",
|
||||
"fiddler crab", "red king crab", "American lobster", "spiny lobster", "crayfish", "hermit crab",
|
||||
"isopod", "white stork", "black stork", "spoonbill", "flamingo", "little blue heron",
|
||||
"great egret", "bittern bird", "crane bird", "limpkin", "common gallinule", "American coot",
|
||||
"bustard", "ruddy turnstone", "dunlin", "common redshank", "dowitcher", "oystercatcher",
|
||||
"pelican", "king penguin", "albatross", "grey whale", "killer whale", "dugong", "sea lion",
|
||||
"Chihuahua", "Japanese Chin", "Maltese", "Pekingese", "Shih Tzu", "King Charles Spaniel",
|
||||
"Papillon", "toy terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset Hound", "Beagle",
|
||||
"Bloodhound", "Bluetick Coonhound", "Black and Tan Coonhound", "Treeing Walker Coonhound",
|
||||
"English foxhound", "Redbone Coonhound", "borzoi", "Irish Wolfhound", "Italian Greyhound",
|
||||
"Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound",
|
||||
"Weimaraner", "Staffordshire Bull Terrier", "American Staffordshire Terrier",
|
||||
"Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier",
|
||||
"Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire Fox Terrier",
|
||||
"Lakeland Terrier", "Sealyham Terrier", "Airedale Terrier", "Cairn Terrier",
|
||||
"Australian Terrier", "Dandie Dinmont Terrier", "Boston Terrier", "Miniature Schnauzer",
|
||||
"Giant Schnauzer", "Standard Schnauzer", "Scottish Terrier", "Tibetan Terrier",
|
||||
"Australian Silky Terrier", "Soft-coated Wheaten Terrier", "West Highland White Terrier",
|
||||
"Lhasa Apso", "Flat-Coated Retriever", "Curly-coated Retriever", "Golden Retriever",
|
||||
"Labrador Retriever", "Chesapeake Bay Retriever", "German Shorthaired Pointer", "Vizsla",
|
||||
"English Setter", "Irish Setter", "Gordon Setter", "Brittany dog", "Clumber Spaniel",
|
||||
"English Springer Spaniel", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel",
|
||||
"Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael dog", "Malinois", "Briard",
|
||||
"Australian Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "collie",
|
||||
"Border Collie", "Bouvier des Flandres dog", "Rottweiler", "German Shepherd Dog", "Dobermann",
|
||||
"Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog",
|
||||
"Appenzeller Sennenhund", "Entlebucher Sennenhund", "Boxer", "Bullmastiff", "Tibetan Mastiff",
|
||||
"French Bulldog", "Great Dane", "St. Bernard", "husky", "Alaskan Malamute", "Siberian Husky",
|
||||
"Dalmatian", "Affenpinscher", "Basenji", "pug", "Leonberger", "Newfoundland dog",
|
||||
"Great Pyrenees dog", "Samoyed", "Pomeranian", "Chow Chow", "Keeshond", "brussels griffon",
|
||||
"Pembroke Welsh Corgi", "Cardigan Welsh Corgi", "Toy Poodle", "Miniature Poodle",
|
||||
"Standard Poodle", "Mexican hairless dog (xoloitzcuintli)", "grey wolf", "Alaskan tundra wolf",
|
||||
"red wolf or maned wolf", "coyote", "dingo", "dhole", "African wild dog", "hyena", "red fox",
|
||||
"kit fox", "Arctic fox", "grey fox", "tabby cat", "tiger cat", "Persian cat", "Siamese cat",
|
||||
"Egyptian Mau", "cougar", "lynx", "leopard", "snow leopard", "jaguar", "lion", "tiger",
|
||||
"cheetah", "brown bear", "American black bear", "polar bear", "sloth bear", "mongoose",
|
||||
"meerkat", "tiger beetle", "ladybug", "ground beetle", "longhorn beetle", "leaf beetle",
|
||||
"dung beetle", "rhinoceros beetle", "weevil", "fly", "bee", "ant", "grasshopper",
|
||||
"cricket insect", "stick insect", "cockroach", "praying mantis", "cicada", "leafhopper",
|
||||
"lacewing", "dragonfly", "damselfly", "red admiral butterfly", "ringlet butterfly",
|
||||
"monarch butterfly", "small white butterfly", "sulphur butterfly", "gossamer-winged butterfly",
|
||||
"starfish", "sea urchin", "sea cucumber", "cottontail rabbit", "hare", "Angora rabbit",
|
||||
"hamster", "porcupine", "fox squirrel", "marmot", "beaver", "guinea pig", "common sorrel horse",
|
||||
"zebra", "pig", "wild boar", "warthog", "hippopotamus", "ox", "water buffalo", "bison",
|
||||
"ram (adult male sheep)", "bighorn sheep", "Alpine ibex", "hartebeest", "impala (antelope)",
|
||||
"gazelle", "arabian camel", "llama", "weasel", "mink", "European polecat",
|
||||
"black-footed ferret", "otter", "skunk", "badger", "armadillo", "three-toed sloth", "orangutan",
|
||||
"gorilla", "chimpanzee", "gibbon", "siamang", "guenon", "patas monkey", "baboon", "macaque",
|
||||
"langur", "black-and-white colobus", "proboscis monkey", "marmoset", "white-headed capuchin",
|
||||
"howler monkey", "titi monkey", "Geoffroy's spider monkey", "common squirrel monkey",
|
||||
"ring-tailed lemur", "indri", "Asian elephant", "African bush elephant", "red panda",
|
||||
"giant panda", "snoek fish", "eel", "silver salmon", "rock beauty fish", "clownfish",
|
||||
"sturgeon", "gar fish", "lionfish", "pufferfish", "abacus", "abaya", "academic gown",
|
||||
"accordion", "acoustic guitar", "aircraft carrier", "airliner", "airship", "altar", "ambulance",
|
||||
"amphibious vehicle", "analog clock", "apiary", "apron", "trash can", "assault rifle",
|
||||
"backpack", "bakery", "balance beam", "balloon", "ballpoint pen", "Band-Aid", "banjo",
|
||||
"baluster / handrail", "barbell", "barber chair", "barbershop", "barn", "barometer", "barrel",
|
||||
"wheelbarrow", "baseball", "basketball", "bassinet", "bassoon", "swimming cap", "bath towel",
|
||||
"bathtub", "station wagon", "lighthouse", "beaker", "military hat (bearskin or shako)",
|
||||
"beer bottle", "beer glass", "bell tower", "baby bib", "tandem bicycle", "bikini",
|
||||
"ring binder", "binoculars", "birdhouse", "boathouse", "bobsleigh", "bolo tie", "poke bonnet",
|
||||
"bookcase", "bookstore", "bottle cap", "hunting bow", "bow tie", "brass memorial plaque", "bra",
|
||||
"breakwater", "breastplate", "broom", "bucket", "buckle", "bulletproof vest",
|
||||
"high-speed train", "butcher shop", "taxicab", "cauldron", "candle", "cannon", "canoe",
|
||||
"can opener", "cardigan", "car mirror", "carousel", "tool kit", "cardboard box / carton",
|
||||
"car wheel", "automated teller machine", "cassette", "cassette player", "castle", "catamaran",
|
||||
"CD player", "cello", "mobile phone", "chain", "chain-link fence", "chain mail", "chainsaw",
|
||||
"storage chest", "chiffonier", "bell or wind chime", "china cabinet", "Christmas stocking",
|
||||
"church", "movie theater", "cleaver", "cliff dwelling", "cloak", "clogs", "cocktail shaker",
|
||||
"coffee mug", "coffeemaker", "spiral or coil", "combination lock", "computer keyboard",
|
||||
"candy store", "container ship", "convertible", "corkscrew", "cornet", "cowboy boot",
|
||||
"cowboy hat", "cradle", "construction crane", "crash helmet", "crate", "infant bed",
|
||||
"Crock Pot", "croquet ball", "crutch", "cuirass", "dam", "desk", "desktop computer",
|
||||
"rotary dial telephone", "diaper", "digital clock", "digital watch", "dining table",
|
||||
"dishcloth", "dishwasher", "disc brake", "dock", "dog sled", "dome", "doormat", "drilling rig",
|
||||
"drum", "drumstick", "dumbbell", "Dutch oven", "electric fan", "electric guitar",
|
||||
"electric locomotive", "entertainment center", "envelope", "espresso machine", "face powder",
|
||||
"feather boa", "filing cabinet", "fireboat", "fire truck", "fire screen", "flagpole", "flute",
|
||||
"folding chair", "football helmet", "forklift", "fountain", "fountain pen", "four-poster bed",
|
||||
"freight car", "French horn", "frying pan", "fur coat", "garbage truck",
|
||||
"gas mask or respirator", "gas pump", "goblet", "go-kart", "golf ball", "golf cart", "gondola",
|
||||
"gong", "gown", "grand piano", "greenhouse", "radiator grille", "grocery store", "guillotine",
|
||||
"hair clip", "hair spray", "half-track", "hammer", "hamper", "hair dryer", "hand-held computer",
|
||||
"handkerchief", "hard disk drive", "harmonica", "harp", "combine harvester", "hatchet",
|
||||
"holster", "home theater", "honeycomb", "hook", "hoop skirt", "gymnastic horizontal bar",
|
||||
"horse-drawn vehicle", "hourglass", "iPod", "clothes iron", "carved pumpkin", "jeans", "jeep",
|
||||
"T-shirt", "jigsaw puzzle", "rickshaw", "joystick", "kimono", "knee pad", "knot", "lab coat",
|
||||
"ladle", "lampshade", "laptop computer", "lawn mower", "lens cap", "letter opener", "library",
|
||||
"lifeboat", "lighter", "limousine", "ocean liner", "lipstick", "slip-on shoe", "lotion",
|
||||
"music speaker", "loupe magnifying glass", "sawmill", "magnetic compass", "messenger bag",
|
||||
"mailbox", "tights", "one-piece bathing suit", "manhole cover", "maraca", "marimba", "mask",
|
||||
"matchstick", "maypole", "maze", "measuring cup", "medicine cabinet", "megalith", "microphone",
|
||||
"microwave oven", "military uniform", "milk can", "minibus", "miniskirt", "minivan", "missile",
|
||||
"mitten", "mixing bowl", "mobile home", "ford model t", "modem", "monastery", "monitor",
|
||||
"moped", "mortar and pestle", "graduation cap", "mosque", "mosquito net", "vespa",
|
||||
"mountain bike", "tent", "computer mouse", "mousetrap", "moving van", "muzzle", "metal nail",
|
||||
"neck brace", "necklace", "baby pacifier", "notebook computer", "obelisk", "oboe", "ocarina",
|
||||
"odometer", "oil filter", "pipe organ", "oscilloscope", "overskirt", "bullock cart",
|
||||
"oxygen mask", "product packet / packaging", "paddle", "paddle wheel", "padlock", "paintbrush",
|
||||
"pajamas", "palace", "pan flute", "paper towel", "parachute", "parallel bars", "park bench",
|
||||
"parking meter", "railroad car", "patio", "payphone", "pedestal", "pencil case",
|
||||
"pencil sharpener", "perfume", "Petri dish", "photocopier", "plectrum", "Pickelhaube",
|
||||
"picket fence", "pickup truck", "pier", "piggy bank", "pill bottle", "pillow", "ping-pong ball",
|
||||
"pinwheel", "pirate ship", "drink pitcher", "block plane", "planetarium", "plastic bag",
|
||||
"plate rack", "farm plow", "plunger", "Polaroid camera", "pole", "police van", "poncho",
|
||||
"pool table", "soda bottle", "plant pot", "potter's wheel", "power drill", "prayer rug",
|
||||
"printer", "prison", "missile", "projector", "hockey puck", "punching bag", "purse", "quill",
|
||||
"quilt", "race car", "racket", "radiator", "radio", "radio telescope", "rain barrel",
|
||||
"recreational vehicle", "fishing casting reel", "reflex camera", "refrigerator",
|
||||
"remote control", "restaurant", "revolver", "rifle", "rocking chair", "rotisserie", "eraser",
|
||||
"rugby ball", "ruler measuring stick", "sneaker", "safe", "safety pin", "salt shaker", "sandal",
|
||||
"sarong", "saxophone", "scabbard", "weighing scale", "school bus", "schooner", "scoreboard",
|
||||
"CRT monitor", "screw", "screwdriver", "seat belt", "sewing machine", "shield", "shoe store",
|
||||
"shoji screen / room divider", "shopping basket", "shopping cart", "shovel", "shower cap",
|
||||
"shower curtain", "ski", "balaclava ski mask", "sleeping bag", "slide rule", "sliding door",
|
||||
"slot machine", "snorkel", "snowmobile", "snowplow", "soap dispenser", "soccer ball", "sock",
|
||||
"solar thermal collector", "sombrero", "soup bowl", "keyboard space bar", "space heater",
|
||||
"space shuttle", "spatula", "motorboat", "spider web", "spindle", "sports car", "spotlight",
|
||||
"stage", "steam locomotive", "through arch bridge", "steel drum", "stethoscope", "scarf",
|
||||
"stone wall", "stopwatch", "stove", "strainer", "tram", "stretcher", "couch", "stupa",
|
||||
"submarine", "suit", "sundial", "sunglasses", "sunglasses", "sunscreen", "suspension bridge",
|
||||
"mop", "sweatshirt", "swim trunks / shorts", "swing", "electrical switch", "syringe",
|
||||
"table lamp", "tank", "tape player", "teapot", "teddy bear", "television", "tennis ball",
|
||||
"thatched roof", "front curtain", "thimble", "threshing machine", "throne", "tile roof",
|
||||
"toaster", "tobacco shop", "toilet seat", "torch", "totem pole", "tow truck", "toy store",
|
||||
"tractor", "semi-trailer truck", "tray", "trench coat", "tricycle", "trimaran", "tripod",
|
||||
"triumphal arch", "trolleybus", "trombone", "hot tub", "turnstile", "typewriter keyboard",
|
||||
"umbrella", "unicycle", "upright piano", "vacuum cleaner", "vase", "vaulted or arched ceiling",
|
||||
"velvet fabric", "vending machine", "vestment", "viaduct", "violin", "volleyball",
|
||||
"waffle iron", "wall clock", "wallet", "wardrobe", "military aircraft", "sink",
|
||||
"washing machine", "water bottle", "water jug", "water tower", "whiskey jug", "whistle",
|
||||
"hair wig", "window screen", "window shade", "Windsor tie", "wine bottle", "airplane wing",
|
||||
"wok", "wooden spoon", "wool", "split-rail fence", "shipwreck", "sailboat", "yurt", "website",
|
||||
"comic book", "crossword", "traffic or street sign", "traffic light", "dust jacket", "menu",
|
||||
"plate", "guacamole", "consomme", "hot pot", "trifle", "ice cream", "popsicle", "baguette",
|
||||
"bagel", "pretzel", "cheeseburger", "hot dog", "mashed potatoes", "cabbage", "broccoli",
|
||||
"cauliflower", "zucchini", "spaghetti squash", "acorn squash", "butternut squash", "cucumber",
|
||||
"artichoke", "bell pepper", "cardoon", "mushroom", "Granny Smith apple", "strawberry", "orange",
|
||||
"lemon", "fig", "pineapple", "banana", "jackfruit", "cherimoya (custard apple)", "pomegranate",
|
||||
"hay", "carbonara", "chocolate syrup", "dough", "meatloaf", "pizza", "pot pie", "burrito",
|
||||
"red wine", "espresso", "tea cup", "eggnog", "mountain", "bubble", "cliff", "coral reef",
|
||||
"geyser", "lakeshore", "promontory", "sandbar", "beach", "valley", "volcano", "baseball player",
|
||||
"bridegroom", "scuba diver", "rapeseed", "daisy", "yellow lady's slipper", "corn", "acorn",
|
||||
"rose hip", "horse chestnut seed", "coral fungus", "agaric", "gyromitra", "stinkhorn mushroom",
|
||||
"earth star fungus", "hen of the woods mushroom", "bolete", "corn cob", "toilet paper"]
|
||||
|
||||
random.seed(1)
|
||||
k_shot = 8
|
||||
# Data loading code
|
||||
data_path = args.data_path_source
|
||||
traindir_source = os.path.join(args.data_path_source, args.src)
|
||||
traindir_target = os.path.join(args.data_path_source_t, args.src_t)
|
||||
valdir = os.path.join(args.data_path_target, args.tar)
|
||||
if not os.path.isdir(traindir_source):
|
||||
# split_train_test_images(args.data_path)
|
||||
raise ValueError('Null path of source train data!!!')
|
||||
|
||||
images = torchvision.datasets.ImageNet(data_path, split='val', transform=preprocess)
|
||||
loader = torch.utils.data.DataLoader(images, batch_size=8, num_workers=8,
|
||||
shuffle=False) # shuffle=True可以对数据进行随机读取,可以对数据进行洗牌操作(shuffling),打乱数据集内数据分布的顺序
|
||||
train_tranform = transforms.Compose([
|
||||
transforms.RandomResizedCrop(size=224, scale=(0.5, 1), interpolation=transforms.InterpolationMode.BICUBIC),
|
||||
# 随机裁剪 但是保留纵横比
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))
|
||||
])
|
||||
train_images = torchvision.datasets.ImageNet(data_path, split='train',
|
||||
transform=train_tranform)
|
||||
split_by_label_dict = defaultdict(list)
|
||||
# split_by_contexts_dict = defaultdict(list)
|
||||
# for i in range(len(imagenet_classes)):
|
||||
# split_by_contexts_dict[i]=[template.format(imagenet_classes[i]) for template in templates]
|
||||
for i in range(len(train_images.imgs)):
|
||||
split_by_label_dict[train_images.targets[i]].append(train_images.imgs[i])
|
||||
# split_by_contexts_dict[train_images.targets[i]]=[template.format(train_images.classes[train_images.targets[i]]) for template in templates]
|
||||
imgs = []
|
||||
targets = []
|
||||
# contexts=[]
|
||||
for label, items in split_by_label_dict.items():
|
||||
imgs = imgs + random.sample(items, k_shot)
|
||||
targets = targets + [label for i in range(k_shot)]
|
||||
# contexts=contexts+[split_by_context_dict[label] for i in range(k_shot)]
|
||||
|
||||
train_images.imgs = imgs
|
||||
train_images.targets = targets
|
||||
train_images.samples = imgs
|
||||
# train_images.classes= contexts
|
||||
|
||||
# train_loader = torch.utils.data.DataLoader(train_images, batch_size=64, num_workers=8, shuffle=False) # 16个样本
|
||||
train_loader_shuffle = torch.utils.data.DataLoader(train_images, batch_size=8, num_workers=8, shuffle=True)#,drop_last=True)
|
||||
|
||||
return train_loader_shuffle, loader
|
||||
33
datasets/__init__.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from .oxford_pets import OxfordPets
|
||||
from .eurosat import EuroSAT
|
||||
from .ucf101 import UCF101
|
||||
from .sun397 import SUN397
|
||||
from .caltech101 import Caltech101
|
||||
from .dtd import DescribableTextures
|
||||
from .fgvc import FGVCAircraft
|
||||
from .food101 import Food101
|
||||
from .oxford_flowers import OxfordFlowers
|
||||
from .stanford_cars import StanfordCars
|
||||
from .imagenet import ImageNet
|
||||
from .caltech101_tsne import Caltech101_TSNE
|
||||
|
||||
|
||||
|
||||
dataset_list = {
|
||||
"oxford_pets": OxfordPets,
|
||||
"eurosat": EuroSAT,
|
||||
"ucf101": UCF101,
|
||||
"sun397": SUN397,
|
||||
"caltech101": Caltech101,
|
||||
"dtd": DescribableTextures,
|
||||
"fgvc": FGVCAircraft,
|
||||
"food101": Food101,
|
||||
"oxford_flowers": OxfordFlowers,
|
||||
"stanford_cars": StanfordCars,
|
||||
"caltech101_tsne": Caltech101_TSNE,
|
||||
"imagenet":ImageNet,
|
||||
}
|
||||
|
||||
|
||||
def build_dataset(dataset, root_path, shots):
|
||||
return dataset_list[dataset](root_path, shots)
|
||||
24
datasets/caltech101.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
from .utils import Datum, DatasetBase
|
||||
from .oxford_pets import OxfordPets
|
||||
|
||||
|
||||
template = ['a photo of a {}.']
|
||||
|
||||
|
||||
class Caltech101(DatasetBase):
|
||||
|
||||
dataset_dir = 'caltech-101'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, '101_ObjectCategories')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_Caltech101.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
t_sne_test = self.generate_fewshot_dataset(test, num_shots=num_shots)
|
||||
super().__init__(train_x=train, val=val, test=test,t_sne=t_sne_test)
|
||||
24
datasets/caltech101_tsne.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
from .utils import Datum, DatasetBase
|
||||
from .oxford_pets import OxfordPets
|
||||
|
||||
|
||||
template = ['a photo of a {}.']
|
||||
|
||||
|
||||
class Caltech101_TSNE(DatasetBase):
|
||||
|
||||
dataset_dir = 'caltech-101_tsne'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, '101_ObjectCategories')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_Caltech101.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
t_sne_test = self.generate_fewshot_dataset(test, num_shots=num_shots)
|
||||
super().__init__(train_x=train, val=val, test=test,t_sne=t_sne_test)
|
||||
79
datasets/dtd.py
Normal file
@@ -0,0 +1,79 @@
|
||||
import os
|
||||
import random
|
||||
|
||||
from .utils import Datum, DatasetBase, listdir_nohidden
|
||||
from .oxford_pets import OxfordPets
|
||||
|
||||
|
||||
template = ['{} texture.']
|
||||
|
||||
|
||||
class DescribableTextures(DatasetBase):
|
||||
|
||||
dataset_dir = 'dtd'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'images')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_DescribableTextures.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
|
||||
@staticmethod
|
||||
def read_and_split_data(
|
||||
image_dir,
|
||||
p_trn=0.5,
|
||||
p_val=0.2,
|
||||
ignored=[],
|
||||
new_cnames=None
|
||||
):
|
||||
# The data are supposed to be organized into the following structure
|
||||
# =============
|
||||
# images/
|
||||
# dog/
|
||||
# cat/
|
||||
# horse/
|
||||
# =============
|
||||
categories = listdir_nohidden(image_dir)
|
||||
categories = [c for c in categories if c not in ignored]
|
||||
categories.sort()
|
||||
|
||||
p_tst = 1 - p_trn - p_val
|
||||
print(f'Splitting into {p_trn:.0%} train, {p_val:.0%} val, and {p_tst:.0%} test')
|
||||
|
||||
def _collate(ims, y, c):
|
||||
items = []
|
||||
for im in ims:
|
||||
item = Datum(
|
||||
impath=im,
|
||||
label=y, # is already 0-based
|
||||
classname=c
|
||||
)
|
||||
items.append(item)
|
||||
return items
|
||||
|
||||
train, val, test = [], [], []
|
||||
for label, category in enumerate(categories):
|
||||
category_dir = os.path.join(image_dir, category)
|
||||
images = listdir_nohidden(category_dir)
|
||||
images = [os.path.join(category_dir, im) for im in images]
|
||||
random.shuffle(images)
|
||||
n_total = len(images)
|
||||
n_train = round(n_total * p_trn)
|
||||
n_val = round(n_total * p_val)
|
||||
n_test = n_total - n_train - n_val
|
||||
assert n_train > 0 and n_val > 0 and n_test > 0
|
||||
|
||||
if new_cnames is not None and category in new_cnames:
|
||||
category = new_cnames[category]
|
||||
|
||||
train.extend(_collate(images[:n_train], label, category))
|
||||
val.extend(_collate(images[n_train:n_train+n_val], label, category))
|
||||
test.extend(_collate(images[n_train+n_val:], label, category))
|
||||
|
||||
return train, val, test
|
||||
50
datasets/eurosat.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
|
||||
from .utils import Datum, DatasetBase, read_json, write_json, build_data_loader
|
||||
from .oxford_pets import OxfordPets
|
||||
|
||||
|
||||
template = ['a centered satellite photo of {}.']
|
||||
|
||||
|
||||
NEW_CNAMES = {
|
||||
'AnnualCrop': 'Annual Crop Land',
|
||||
'Forest': 'Forest',
|
||||
'HerbaceousVegetation': 'Herbaceous Vegetation Land',
|
||||
'Highway': 'Highway or Road',
|
||||
'Industrial': 'Industrial Buildings',
|
||||
'Pasture': 'Pasture Land',
|
||||
'PermanentCrop': 'Permanent Crop Land',
|
||||
'Residential': 'Residential Buildings',
|
||||
'River': 'River',
|
||||
'SeaLake': 'Sea or Lake'
|
||||
}
|
||||
|
||||
|
||||
class EuroSAT(DatasetBase):
|
||||
|
||||
dataset_dir = 'eurosat'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, '2750')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_EuroSAT.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
|
||||
def update_classname(self, dataset_old):
|
||||
dataset_new = []
|
||||
for item_old in dataset_old:
|
||||
cname_old = item_old.classname
|
||||
cname_new = NEW_CLASSNAMES[cname_old]
|
||||
item_new = Datum(
|
||||
impath=item_old.impath,
|
||||
label=item_old.label,
|
||||
classname=cname_new
|
||||
)
|
||||
dataset_new.append(item_new)
|
||||
return dataset_new
|
||||
54
datasets/fgvc.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
|
||||
from .utils import Datum, DatasetBase, read_json, write_json, build_data_loader
|
||||
|
||||
|
||||
template = ['a photo of a {}, a type of aircraft.']
|
||||
|
||||
|
||||
class FGVCAircraft(DatasetBase):
|
||||
|
||||
dataset_dir = 'fgvc_aircraft'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'images')
|
||||
|
||||
self.template = template
|
||||
|
||||
classnames = []
|
||||
with open(os.path.join(self.dataset_dir, 'variants.txt'), 'r') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
classnames.append(line.strip())
|
||||
cname2lab = {c: i for i, c in enumerate(classnames)}
|
||||
|
||||
train = self.read_data(cname2lab, 'images_variant_train.txt')
|
||||
val = self.read_data(cname2lab, 'images_variant_val.txt')
|
||||
test = self.read_data(cname2lab, 'images_variant_test.txt')
|
||||
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
|
||||
def read_data(self, cname2lab, split_file):
|
||||
filepath = os.path.join(self.dataset_dir, split_file)
|
||||
items = []
|
||||
|
||||
with open(filepath, 'r') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line = line.strip().split(' ')
|
||||
imname = line[0] + '.jpg'
|
||||
classname = ' '.join(line[1:])
|
||||
impath = os.path.join(self.image_dir, imname)
|
||||
label = cname2lab[classname]
|
||||
item = Datum(
|
||||
impath=impath,
|
||||
label=label,
|
||||
classname=classname
|
||||
)
|
||||
items.append(item)
|
||||
|
||||
return items
|
||||
24
datasets/food101.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
from .utils import Datum, DatasetBase, read_json, write_json, build_data_loader
|
||||
from .oxford_pets import OxfordPets
|
||||
|
||||
|
||||
template = ['a photo of {}, a type of food.']
|
||||
|
||||
|
||||
class Food101(DatasetBase):
|
||||
|
||||
dataset_dir = 'food-101'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'images')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_Food101.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
221
datasets/imagenet.py
Normal file
@@ -0,0 +1,221 @@
|
||||
import os
|
||||
import math
|
||||
import random
|
||||
from collections import defaultdict
|
||||
|
||||
import torch
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
|
||||
|
||||
imagenet_classes = ["tench", "goldfish", "great white shark", "tiger shark", "hammerhead shark", "electric ray",
|
||||
"stingray", "rooster", "hen", "ostrich", "brambling", "goldfinch", "house finch", "junco",
|
||||
"indigo bunting", "American robin", "bulbul", "jay", "magpie", "chickadee", "American dipper",
|
||||
"kite (bird of prey)", "bald eagle", "vulture", "great grey owl", "fire salamander",
|
||||
"smooth newt", "newt", "spotted salamander", "axolotl", "American bullfrog", "tree frog",
|
||||
"tailed frog", "loggerhead sea turtle", "leatherback sea turtle", "mud turtle", "terrapin",
|
||||
"box turtle", "banded gecko", "green iguana", "Carolina anole",
|
||||
"desert grassland whiptail lizard", "agama", "frilled-necked lizard", "alligator lizard",
|
||||
"Gila monster", "European green lizard", "chameleon", "Komodo dragon", "Nile crocodile",
|
||||
"American alligator", "triceratops", "worm snake", "ring-necked snake",
|
||||
"eastern hog-nosed snake", "smooth green snake", "kingsnake", "garter snake", "water snake",
|
||||
"vine snake", "night snake", "boa constrictor", "African rock python", "Indian cobra",
|
||||
"green mamba", "sea snake", "Saharan horned viper", "eastern diamondback rattlesnake",
|
||||
"sidewinder rattlesnake", "trilobite", "harvestman", "scorpion", "yellow garden spider",
|
||||
"barn spider", "European garden spider", "southern black widow", "tarantula", "wolf spider",
|
||||
"tick", "centipede", "black grouse", "ptarmigan", "ruffed grouse", "prairie grouse", "peafowl",
|
||||
"quail", "partridge", "african grey parrot", "macaw", "sulphur-crested cockatoo", "lorikeet",
|
||||
"coucal", "bee eater", "hornbill", "hummingbird", "jacamar", "toucan", "duck",
|
||||
"red-breasted merganser", "goose", "black swan", "tusker", "echidna", "platypus", "wallaby",
|
||||
"koala", "wombat", "jellyfish", "sea anemone", "brain coral", "flatworm", "nematode", "conch",
|
||||
"snail", "slug", "sea slug", "chiton", "chambered nautilus", "Dungeness crab", "rock crab",
|
||||
"fiddler crab", "red king crab", "American lobster", "spiny lobster", "crayfish", "hermit crab",
|
||||
"isopod", "white stork", "black stork", "spoonbill", "flamingo", "little blue heron",
|
||||
"great egret", "bittern bird", "crane bird", "limpkin", "common gallinule", "American coot",
|
||||
"bustard", "ruddy turnstone", "dunlin", "common redshank", "dowitcher", "oystercatcher",
|
||||
"pelican", "king penguin", "albatross", "grey whale", "killer whale", "dugong", "sea lion",
|
||||
"Chihuahua", "Japanese Chin", "Maltese", "Pekingese", "Shih Tzu", "King Charles Spaniel",
|
||||
"Papillon", "toy terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset Hound", "Beagle",
|
||||
"Bloodhound", "Bluetick Coonhound", "Black and Tan Coonhound", "Treeing Walker Coonhound",
|
||||
"English foxhound", "Redbone Coonhound", "borzoi", "Irish Wolfhound", "Italian Greyhound",
|
||||
"Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound",
|
||||
"Weimaraner", "Staffordshire Bull Terrier", "American Staffordshire Terrier",
|
||||
"Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier",
|
||||
"Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire Fox Terrier",
|
||||
"Lakeland Terrier", "Sealyham Terrier", "Airedale Terrier", "Cairn Terrier",
|
||||
"Australian Terrier", "Dandie Dinmont Terrier", "Boston Terrier", "Miniature Schnauzer",
|
||||
"Giant Schnauzer", "Standard Schnauzer", "Scottish Terrier", "Tibetan Terrier",
|
||||
"Australian Silky Terrier", "Soft-coated Wheaten Terrier", "West Highland White Terrier",
|
||||
"Lhasa Apso", "Flat-Coated Retriever", "Curly-coated Retriever", "Golden Retriever",
|
||||
"Labrador Retriever", "Chesapeake Bay Retriever", "German Shorthaired Pointer", "Vizsla",
|
||||
"English Setter", "Irish Setter", "Gordon Setter", "Brittany dog", "Clumber Spaniel",
|
||||
"English Springer Spaniel", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel",
|
||||
"Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael dog", "Malinois", "Briard",
|
||||
"Australian Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "collie",
|
||||
"Border Collie", "Bouvier des Flandres dog", "Rottweiler", "German Shepherd Dog", "Dobermann",
|
||||
"Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog",
|
||||
"Appenzeller Sennenhund", "Entlebucher Sennenhund", "Boxer", "Bullmastiff", "Tibetan Mastiff",
|
||||
"French Bulldog", "Great Dane", "St. Bernard", "husky", "Alaskan Malamute", "Siberian Husky",
|
||||
"Dalmatian", "Affenpinscher", "Basenji", "pug", "Leonberger", "Newfoundland dog",
|
||||
"Great Pyrenees dog", "Samoyed", "Pomeranian", "Chow Chow", "Keeshond", "brussels griffon",
|
||||
"Pembroke Welsh Corgi", "Cardigan Welsh Corgi", "Toy Poodle", "Miniature Poodle",
|
||||
"Standard Poodle", "Mexican hairless dog (xoloitzcuintli)", "grey wolf", "Alaskan tundra wolf",
|
||||
"red wolf or maned wolf", "coyote", "dingo", "dhole", "African wild dog", "hyena", "red fox",
|
||||
"kit fox", "Arctic fox", "grey fox", "tabby cat", "tiger cat", "Persian cat", "Siamese cat",
|
||||
"Egyptian Mau", "cougar", "lynx", "leopard", "snow leopard", "jaguar", "lion", "tiger",
|
||||
"cheetah", "brown bear", "American black bear", "polar bear", "sloth bear", "mongoose",
|
||||
"meerkat", "tiger beetle", "ladybug", "ground beetle", "longhorn beetle", "leaf beetle",
|
||||
"dung beetle", "rhinoceros beetle", "weevil", "fly", "bee", "ant", "grasshopper",
|
||||
"cricket insect", "stick insect", "cockroach", "praying mantis", "cicada", "leafhopper",
|
||||
"lacewing", "dragonfly", "damselfly", "red admiral butterfly", "ringlet butterfly",
|
||||
"monarch butterfly", "small white butterfly", "sulphur butterfly", "gossamer-winged butterfly",
|
||||
"starfish", "sea urchin", "sea cucumber", "cottontail rabbit", "hare", "Angora rabbit",
|
||||
"hamster", "porcupine", "fox squirrel", "marmot", "beaver", "guinea pig", "common sorrel horse",
|
||||
"zebra", "pig", "wild boar", "warthog", "hippopotamus", "ox", "water buffalo", "bison",
|
||||
"ram (adult male sheep)", "bighorn sheep", "Alpine ibex", "hartebeest", "impala (antelope)",
|
||||
"gazelle", "arabian camel", "llama", "weasel", "mink", "European polecat",
|
||||
"black-footed ferret", "otter", "skunk", "badger", "armadillo", "three-toed sloth", "orangutan",
|
||||
"gorilla", "chimpanzee", "gibbon", "siamang", "guenon", "patas monkey", "baboon", "macaque",
|
||||
"langur", "black-and-white colobus", "proboscis monkey", "marmoset", "white-headed capuchin",
|
||||
"howler monkey", "titi monkey", "Geoffroy's spider monkey", "common squirrel monkey",
|
||||
"ring-tailed lemur", "indri", "Asian elephant", "African bush elephant", "red panda",
|
||||
"giant panda", "snoek fish", "eel", "silver salmon", "rock beauty fish", "clownfish",
|
||||
"sturgeon", "gar fish", "lionfish", "pufferfish", "abacus", "abaya", "academic gown",
|
||||
"accordion", "acoustic guitar", "aircraft carrier", "airliner", "airship", "altar", "ambulance",
|
||||
"amphibious vehicle", "analog clock", "apiary", "apron", "trash can", "assault rifle",
|
||||
"backpack", "bakery", "balance beam", "balloon", "ballpoint pen", "Band-Aid", "banjo",
|
||||
"baluster / handrail", "barbell", "barber chair", "barbershop", "barn", "barometer", "barrel",
|
||||
"wheelbarrow", "baseball", "basketball", "bassinet", "bassoon", "swimming cap", "bath towel",
|
||||
"bathtub", "station wagon", "lighthouse", "beaker", "military hat (bearskin or shako)",
|
||||
"beer bottle", "beer glass", "bell tower", "baby bib", "tandem bicycle", "bikini",
|
||||
"ring binder", "binoculars", "birdhouse", "boathouse", "bobsleigh", "bolo tie", "poke bonnet",
|
||||
"bookcase", "bookstore", "bottle cap", "hunting bow", "bow tie", "brass memorial plaque", "bra",
|
||||
"breakwater", "breastplate", "broom", "bucket", "buckle", "bulletproof vest",
|
||||
"high-speed train", "butcher shop", "taxicab", "cauldron", "candle", "cannon", "canoe",
|
||||
"can opener", "cardigan", "car mirror", "carousel", "tool kit", "cardboard box / carton",
|
||||
"car wheel", "automated teller machine", "cassette", "cassette player", "castle", "catamaran",
|
||||
"CD player", "cello", "mobile phone", "chain", "chain-link fence", "chain mail", "chainsaw",
|
||||
"storage chest", "chiffonier", "bell or wind chime", "china cabinet", "Christmas stocking",
|
||||
"church", "movie theater", "cleaver", "cliff dwelling", "cloak", "clogs", "cocktail shaker",
|
||||
"coffee mug", "coffeemaker", "spiral or coil", "combination lock", "computer keyboard",
|
||||
"candy store", "container ship", "convertible", "corkscrew", "cornet", "cowboy boot",
|
||||
"cowboy hat", "cradle", "construction crane", "crash helmet", "crate", "infant bed",
|
||||
"Crock Pot", "croquet ball", "crutch", "cuirass", "dam", "desk", "desktop computer",
|
||||
"rotary dial telephone", "diaper", "digital clock", "digital watch", "dining table",
|
||||
"dishcloth", "dishwasher", "disc brake", "dock", "dog sled", "dome", "doormat", "drilling rig",
|
||||
"drum", "drumstick", "dumbbell", "Dutch oven", "electric fan", "electric guitar",
|
||||
"electric locomotive", "entertainment center", "envelope", "espresso machine", "face powder",
|
||||
"feather boa", "filing cabinet", "fireboat", "fire truck", "fire screen", "flagpole", "flute",
|
||||
"folding chair", "football helmet", "forklift", "fountain", "fountain pen", "four-poster bed",
|
||||
"freight car", "French horn", "frying pan", "fur coat", "garbage truck",
|
||||
"gas mask or respirator", "gas pump", "goblet", "go-kart", "golf ball", "golf cart", "gondola",
|
||||
"gong", "gown", "grand piano", "greenhouse", "radiator grille", "grocery store", "guillotine",
|
||||
"hair clip", "hair spray", "half-track", "hammer", "hamper", "hair dryer", "hand-held computer",
|
||||
"handkerchief", "hard disk drive", "harmonica", "harp", "combine harvester", "hatchet",
|
||||
"holster", "home theater", "honeycomb", "hook", "hoop skirt", "gymnastic horizontal bar",
|
||||
"horse-drawn vehicle", "hourglass", "iPod", "clothes iron", "carved pumpkin", "jeans", "jeep",
|
||||
"T-shirt", "jigsaw puzzle", "rickshaw", "joystick", "kimono", "knee pad", "knot", "lab coat",
|
||||
"ladle", "lampshade", "laptop computer", "lawn mower", "lens cap", "letter opener", "library",
|
||||
"lifeboat", "lighter", "limousine", "ocean liner", "lipstick", "slip-on shoe", "lotion",
|
||||
"music speaker", "loupe magnifying glass", "sawmill", "magnetic compass", "messenger bag",
|
||||
"mailbox", "tights", "one-piece bathing suit", "manhole cover", "maraca", "marimba", "mask",
|
||||
"matchstick", "maypole", "maze", "measuring cup", "medicine cabinet", "megalith", "microphone",
|
||||
"microwave oven", "military uniform", "milk can", "minibus", "miniskirt", "minivan", "missile",
|
||||
"mitten", "mixing bowl", "mobile home", "ford model t", "modem", "monastery", "monitor",
|
||||
"moped", "mortar and pestle", "graduation cap", "mosque", "mosquito net", "vespa",
|
||||
"mountain bike", "tent", "computer mouse", "mousetrap", "moving van", "muzzle", "metal nail",
|
||||
"neck brace", "necklace", "baby pacifier", "notebook computer", "obelisk", "oboe", "ocarina",
|
||||
"odometer", "oil filter", "pipe organ", "oscilloscope", "overskirt", "bullock cart",
|
||||
"oxygen mask", "product packet / packaging", "paddle", "paddle wheel", "padlock", "paintbrush",
|
||||
"pajamas", "palace", "pan flute", "paper towel", "parachute", "parallel bars", "park bench",
|
||||
"parking meter", "railroad car", "patio", "payphone", "pedestal", "pencil case",
|
||||
"pencil sharpener", "perfume", "Petri dish", "photocopier", "plectrum", "Pickelhaube",
|
||||
"picket fence", "pickup truck", "pier", "piggy bank", "pill bottle", "pillow", "ping-pong ball",
|
||||
"pinwheel", "pirate ship", "drink pitcher", "block plane", "planetarium", "plastic bag",
|
||||
"plate rack", "farm plow", "plunger", "Polaroid camera", "pole", "police van", "poncho",
|
||||
"pool table", "soda bottle", "plant pot", "potter's wheel", "power drill", "prayer rug",
|
||||
"printer", "prison", "missile", "projector", "hockey puck", "punching bag", "purse", "quill",
|
||||
"quilt", "race car", "racket", "radiator", "radio", "radio telescope", "rain barrel",
|
||||
"recreational vehicle", "fishing casting reel", "reflex camera", "refrigerator",
|
||||
"remote control", "restaurant", "revolver", "rifle", "rocking chair", "rotisserie", "eraser",
|
||||
"rugby ball", "ruler measuring stick", "sneaker", "safe", "safety pin", "salt shaker", "sandal",
|
||||
"sarong", "saxophone", "scabbard", "weighing scale", "school bus", "schooner", "scoreboard",
|
||||
"CRT monitor", "screw", "screwdriver", "seat belt", "sewing machine", "shield", "shoe store",
|
||||
"shoji screen / room divider", "shopping basket", "shopping cart", "shovel", "shower cap",
|
||||
"shower curtain", "ski", "balaclava ski mask", "sleeping bag", "slide rule", "sliding door",
|
||||
"slot machine", "snorkel", "snowmobile", "snowplow", "soap dispenser", "soccer ball", "sock",
|
||||
"solar thermal collector", "sombrero", "soup bowl", "keyboard space bar", "space heater",
|
||||
"space shuttle", "spatula", "motorboat", "spider web", "spindle", "sports car", "spotlight",
|
||||
"stage", "steam locomotive", "through arch bridge", "steel drum", "stethoscope", "scarf",
|
||||
"stone wall", "stopwatch", "stove", "strainer", "tram", "stretcher", "couch", "stupa",
|
||||
"submarine", "suit", "sundial", "sunglasses", "sunglasses", "sunscreen", "suspension bridge",
|
||||
"mop", "sweatshirt", "swim trunks / shorts", "swing", "electrical switch", "syringe",
|
||||
"table lamp", "tank", "tape player", "teapot", "teddy bear", "television", "tennis ball",
|
||||
"thatched roof", "front curtain", "thimble", "threshing machine", "throne", "tile roof",
|
||||
"toaster", "tobacco shop", "toilet seat", "torch", "totem pole", "tow truck", "toy store",
|
||||
"tractor", "semi-trailer truck", "tray", "trench coat", "tricycle", "trimaran", "tripod",
|
||||
"triumphal arch", "trolleybus", "trombone", "hot tub", "turnstile", "typewriter keyboard",
|
||||
"umbrella", "unicycle", "upright piano", "vacuum cleaner", "vase", "vaulted or arched ceiling",
|
||||
"velvet fabric", "vending machine", "vestment", "viaduct", "violin", "volleyball",
|
||||
"waffle iron", "wall clock", "wallet", "wardrobe", "military aircraft", "sink",
|
||||
"washing machine", "water bottle", "water jug", "water tower", "whiskey jug", "whistle",
|
||||
"hair wig", "window screen", "window shade", "Windsor tie", "wine bottle", "airplane wing",
|
||||
"wok", "wooden spoon", "wool", "split-rail fence", "shipwreck", "sailboat", "yurt", "website",
|
||||
"comic book", "crossword", "traffic or street sign", "traffic light", "dust jacket", "menu",
|
||||
"plate", "guacamole", "consomme", "hot pot", "trifle", "ice cream", "popsicle", "baguette",
|
||||
"bagel", "pretzel", "cheeseburger", "hot dog", "mashed potatoes", "cabbage", "broccoli",
|
||||
"cauliflower", "zucchini", "spaghetti squash", "acorn squash", "butternut squash", "cucumber",
|
||||
"artichoke", "bell pepper", "cardoon", "mushroom", "Granny Smith apple", "strawberry", "orange",
|
||||
"lemon", "fig", "pineapple", "banana", "jackfruit", "cherimoya (custard apple)", "pomegranate",
|
||||
"hay", "carbonara", "chocolate syrup", "dough", "meatloaf", "pizza", "pot pie", "burrito",
|
||||
"red wine", "espresso", "tea cup", "eggnog", "mountain", "bubble", "cliff", "coral reef",
|
||||
"geyser", "lakeshore", "promontory", "sandbar", "beach", "valley", "volcano", "baseball player",
|
||||
"bridegroom", "scuba diver", "rapeseed", "daisy", "yellow lady's slipper", "corn", "acorn",
|
||||
"rose hip", "horse chestnut seed", "coral fungus", "agaric", "gyromitra", "stinkhorn mushroom",
|
||||
"earth star fungus", "hen of the woods mushroom", "bolete", "corn cob", "toilet paper"]
|
||||
|
||||
imagenet_templates = ["itap of a {}.",
|
||||
"a bad photo of the {}.",
|
||||
"a origami {}.",
|
||||
"a photo of the large {}.",
|
||||
"a {} in a video game.",
|
||||
"art of the {}.",
|
||||
"a photo of the small {}."]
|
||||
|
||||
|
||||
class ImageNet():
|
||||
|
||||
dataset_dir = 'imagenet'
|
||||
|
||||
def __init__(self, root, num_shots, preprocess):
|
||||
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'images')
|
||||
|
||||
train_preprocess = transforms.Compose([
|
||||
transforms.RandomResizedCrop(size=224, scale=(0.5, 1), interpolation=transforms.InterpolationMode.BICUBIC),
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))
|
||||
])
|
||||
test_preprocess = preprocess
|
||||
|
||||
self.train = torchvision.datasets.ImageNet(self.image_dir, split='train', transform=train_preprocess)
|
||||
self.val = torchvision.datasets.ImageNet(self.image_dir, split='val', transform=test_preprocess)
|
||||
self.test = torchvision.datasets.ImageNet(self.image_dir, split='val', transform=test_preprocess)
|
||||
|
||||
self.template = imagenet_templates
|
||||
self.classnames = imagenet_classes
|
||||
|
||||
split_by_label_dict = defaultdict(list)
|
||||
for i in range(len(self.train.imgs)):
|
||||
split_by_label_dict[self.train.targets[i]].append(self.train.imgs[i])
|
||||
imgs = []
|
||||
targets = []
|
||||
|
||||
for label, items in split_by_label_dict.items():
|
||||
imgs = imgs + random.sample(items, num_shots)
|
||||
targets = targets + [label for i in range(num_shots)]
|
||||
self.train.imgs = imgs
|
||||
self.train.targets = targets
|
||||
self.train.samples = imgs
|
||||
76
datasets/imagenet_sketch.py
Normal file
@@ -0,0 +1,76 @@
|
||||
import os
|
||||
import math
|
||||
import random
|
||||
from collections import defaultdict
|
||||
from .utils import Datum, DatasetBase, read_json, write_json, build_data_loader
|
||||
|
||||
import torch
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
def read_classnames(text_file):
|
||||
"""Return a dictionary containing
|
||||
key-value pairs of <folder name>: <class name>.
|
||||
"""
|
||||
classnames = OrderedDict()
|
||||
with open(text_file, "r") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line = line.strip().split(" ")
|
||||
folder = line[0]
|
||||
classname = " ".join(line[1:])
|
||||
classnames[folder] = classname
|
||||
return classnames
|
||||
|
||||
def listdir_nohidden(path, sort=False):
|
||||
"""List non-hidden items in a directory.
|
||||
|
||||
Args:
|
||||
path (str): directory path.
|
||||
sort (bool): sort the items.
|
||||
"""
|
||||
items = [f for f in os.listdir(path) if not f.startswith(".")]
|
||||
if sort:
|
||||
items.sort()
|
||||
return items
|
||||
class ImageNetSketch(DatasetBase):
|
||||
"""ImageNet-Sketch.
|
||||
|
||||
This dataset is used for testing only.
|
||||
"""
|
||||
|
||||
dataset_dir ="imagenet_sketch"
|
||||
|
||||
def __init__(self, data_dir):
|
||||
root = data_dir
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'images')
|
||||
|
||||
|
||||
text_file = os.path.join(self.dataset_dir, "classnames.txt")
|
||||
classnames = read_classnames(text_file)
|
||||
|
||||
data = self.read_data(classnames)
|
||||
|
||||
super().__init__(train_x=data, val=data, test=data)
|
||||
|
||||
def read_data(self, classnames):
|
||||
image_dir = self.image_dir
|
||||
folders = listdir_nohidden(image_dir, sort=True)
|
||||
items = []
|
||||
|
||||
for label, folder in enumerate(folders):
|
||||
imnames = listdir_nohidden(os.path.join(image_dir, folder))
|
||||
classname = classnames[folder]
|
||||
for imname in imnames:
|
||||
impath = os.path.join(image_dir, folder, imname)
|
||||
item = Datum(
|
||||
impath=impath,
|
||||
label=label,
|
||||
classname=classname
|
||||
)
|
||||
items.append(item)
|
||||
|
||||
return items
|
||||
82
datasets/imagenetv2.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import os
|
||||
import math
|
||||
import random
|
||||
from collections import defaultdict
|
||||
from .utils import Datum, DatasetBase, read_json, write_json, build_data_loader
|
||||
|
||||
import torch
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
|
||||
def read_classnames(text_file):
|
||||
"""Return a dictionary containing
|
||||
key-value pairs of <folder name>: <class name>.
|
||||
"""
|
||||
classnames = OrderedDict()
|
||||
with open(text_file, "r") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line = line.strip().split(" ")
|
||||
folder = line[0]
|
||||
classname = " ".join(line[1:])
|
||||
classnames[folder] = classname
|
||||
return classnames
|
||||
|
||||
def listdir_nohidden(path, sort=False):
|
||||
"""List non-hidden items in a directory.
|
||||
|
||||
Args:
|
||||
path (str): directory path.
|
||||
sort (bool): sort the items.
|
||||
"""
|
||||
items = [f for f in os.listdir(path) if not f.startswith(".")]
|
||||
if sort:
|
||||
items.sort()
|
||||
return items
|
||||
class ImageNetV2(DatasetBase):
|
||||
"""ImageNetV2.
|
||||
|
||||
This dataset is used for testing only.
|
||||
"""
|
||||
|
||||
dataset_dir ="imagenetv2"
|
||||
|
||||
def __init__(self, root):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'imagenetv2')
|
||||
|
||||
|
||||
text_file = os.path.join(self.dataset_dir, "classnames.txt")
|
||||
|
||||
classnames = read_classnames(text_file)
|
||||
|
||||
data = self.read_data(classnames)
|
||||
|
||||
super().__init__(train_x=data, val=data, test=data)
|
||||
def read_data(self, classnames):
|
||||
image_dir = self.image_dir
|
||||
folders = list(classnames.keys())
|
||||
items = []
|
||||
|
||||
for label in range(1000):
|
||||
class_dir = os.path.join(image_dir, str(label))
|
||||
imnames = listdir_nohidden(class_dir)
|
||||
folder = folders[label]
|
||||
classname = classnames[folder]
|
||||
for imname in imnames:
|
||||
impath = os.path.join(class_dir, imname)
|
||||
# item = {"impath": impath, "label": label, "classname": classname}
|
||||
item = Datum(
|
||||
impath=impath,
|
||||
label=label,
|
||||
classname=classname
|
||||
)
|
||||
items.append(item)
|
||||
|
||||
return items
|
||||
|
||||
|
||||
|
||||
67
datasets/oxford_flowers.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import os
|
||||
import random
|
||||
from scipy.io import loadmat
|
||||
from collections import defaultdict
|
||||
|
||||
from .oxford_pets import OxfordPets
|
||||
from .utils import Datum, DatasetBase, read_json
|
||||
|
||||
|
||||
template = ['a photo of a {}, a type of flower.']
|
||||
|
||||
|
||||
class OxfordFlowers(DatasetBase):
|
||||
|
||||
dataset_dir = 'oxford_flowers'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'jpg')
|
||||
self.label_file = os.path.join(self.dataset_dir, 'imagelabels.mat')
|
||||
self.lab2cname_file = os.path.join(self.dataset_dir, 'cat_to_name.json')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_OxfordFlowers.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
|
||||
def read_data(self):
|
||||
tracker = defaultdict(list)
|
||||
label_file = loadmat(self.label_file)['labels'][0]
|
||||
for i, label in enumerate(label_file):
|
||||
imname = f'image_{str(i + 1).zfill(5)}.jpg'
|
||||
impath = os.path.join(self.image_dir, imname)
|
||||
label = int(label)
|
||||
tracker[label].append(impath)
|
||||
|
||||
print('Splitting data into 50% train, 20% val, and 30% test')
|
||||
|
||||
def _collate(ims, y, c):
|
||||
items = []
|
||||
for im in ims:
|
||||
item = Datum(
|
||||
impath=im,
|
||||
label=y-1, # convert to 0-based label
|
||||
classname=c
|
||||
)
|
||||
items.append(item)
|
||||
return items
|
||||
|
||||
lab2cname = read_json(self.lab2cname_file)
|
||||
train, val, test = [], [], []
|
||||
for label, impaths in tracker.items():
|
||||
random.shuffle(impaths)
|
||||
n_total = len(impaths)
|
||||
n_train = round(n_total * 0.5)
|
||||
n_val = round(n_total * 0.2)
|
||||
n_test = n_total - n_train - n_val
|
||||
assert n_train > 0 and n_val > 0 and n_test > 0
|
||||
cname = lab2cname[str(label)]
|
||||
train.extend(_collate(impaths[:n_train], label, cname))
|
||||
val.extend(_collate(impaths[n_train:n_train+n_val], label, cname))
|
||||
test.extend(_collate(impaths[n_train+n_val:], label, cname))
|
||||
|
||||
return train, val, test
|
||||
125
datasets/oxford_pets.py
Normal file
@@ -0,0 +1,125 @@
|
||||
import os
|
||||
import math
|
||||
import random
|
||||
from collections import defaultdict
|
||||
|
||||
import torchvision.transforms as transforms
|
||||
|
||||
from .utils import Datum, DatasetBase, read_json, write_json, build_data_loader
|
||||
|
||||
|
||||
template = ['a photo of a {}, a type of pet.']
|
||||
|
||||
|
||||
class OxfordPets(DatasetBase):
|
||||
|
||||
dataset_dir = 'oxford_pets'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'images')
|
||||
self.anno_dir = os.path.join(self.dataset_dir, 'annotations')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_OxfordPets.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = self.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
|
||||
def read_data(self, split_file):
|
||||
filepath = os.path.join(self.anno_dir, split_file)
|
||||
items = []
|
||||
|
||||
with open(filepath, 'r') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
imname, label, species, _ = line.split(' ')
|
||||
breed = imname.split('_')[:-1]
|
||||
breed = '_'.join(breed)
|
||||
breed = breed.lower()
|
||||
imname += '.jpg'
|
||||
impath = os.path.join(self.image_dir, imname)
|
||||
label = int(label) - 1 # convert to 0-based index
|
||||
item = Datum(
|
||||
impath=impath,
|
||||
label=label,
|
||||
classname=breed
|
||||
)
|
||||
items.append(item)
|
||||
|
||||
return items
|
||||
|
||||
@staticmethod
|
||||
def split_trainval(trainval, p_val=0.2):
|
||||
p_trn = 1 - p_val
|
||||
print(f'Splitting trainval into {p_trn:.0%} train and {p_val:.0%} val')
|
||||
tracker = defaultdict(list)
|
||||
for idx, item in enumerate(trainval):
|
||||
label = item.label
|
||||
tracker[label].append(idx)
|
||||
|
||||
train, val = [], []
|
||||
for label, idxs in tracker.items():
|
||||
n_val = round(len(idxs) * p_val)
|
||||
assert n_val > 0
|
||||
random.shuffle(idxs)
|
||||
for n, idx in enumerate(idxs):
|
||||
item = trainval[idx]
|
||||
if n < n_val:
|
||||
val.append(item)
|
||||
else:
|
||||
train.append(item)
|
||||
|
||||
return train, val
|
||||
|
||||
@staticmethod
|
||||
def save_split(train, val, test, filepath, path_prefix):
|
||||
def _extract(items):
|
||||
out = []
|
||||
for item in items:
|
||||
impath = item.impath
|
||||
label = item.label
|
||||
classname = item.classname
|
||||
impath = impath.replace(path_prefix, '')
|
||||
if impath.startswith('/'):
|
||||
impath = impath[1:]
|
||||
out.append((impath, label, classname))
|
||||
return out
|
||||
|
||||
train = _extract(train)
|
||||
val = _extract(val)
|
||||
test = _extract(test)
|
||||
|
||||
split = {
|
||||
'train': train,
|
||||
'val': val,
|
||||
'test': test
|
||||
}
|
||||
|
||||
write_json(split, filepath)
|
||||
print(f'Saved split to {filepath}')
|
||||
|
||||
@staticmethod
|
||||
def read_split(filepath, path_prefix):
|
||||
def _convert(items):
|
||||
out = []
|
||||
for impath, label, classname in items:
|
||||
impath = os.path.join(path_prefix, impath)
|
||||
item = Datum(
|
||||
impath=impath,
|
||||
label=int(label),
|
||||
classname=classname
|
||||
)
|
||||
out.append(item)
|
||||
return out
|
||||
|
||||
print(f'Reading split from {filepath}')
|
||||
split = read_json(filepath)
|
||||
train = _convert(split['train'])
|
||||
val = _convert(split['val'])
|
||||
test = _convert(split['test'])
|
||||
|
||||
return train, val, test
|
||||
48
datasets/stanford_cars.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import os
|
||||
from scipy.io import loadmat
|
||||
|
||||
from .oxford_pets import OxfordPets
|
||||
from .utils import Datum, DatasetBase
|
||||
|
||||
|
||||
template = ['a photo of a {}.']
|
||||
|
||||
|
||||
class StanfordCars(DatasetBase):
|
||||
|
||||
dataset_dir = 'stanford_cars'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_StanfordCars.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.dataset_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
|
||||
def read_data(self, image_dir, anno_file, meta_file):
|
||||
anno_file = loadmat(anno_file)['annotations'][0]
|
||||
meta_file = loadmat(meta_file)['class_names'][0]
|
||||
items = []
|
||||
|
||||
for i in range(len(anno_file)):
|
||||
imname = anno_file[i]['fname'][0]
|
||||
impath = os.path.join(self.dataset_dir, image_dir, imname)
|
||||
label = anno_file[i]['class'][0, 0]
|
||||
label = int(label) - 1 # convert to 0-based index
|
||||
classname = meta_file[label][0]
|
||||
names = classname.split(' ')
|
||||
year = names.pop(-1)
|
||||
names.insert(0, year)
|
||||
classname = ' '.join(names)
|
||||
item = Datum(
|
||||
impath=impath,
|
||||
label=label,
|
||||
classname=classname
|
||||
)
|
||||
items.append(item)
|
||||
|
||||
return items
|
||||
50
datasets/sun397.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
|
||||
from .utils import Datum, DatasetBase, read_json, write_json, build_data_loader
|
||||
|
||||
from .oxford_pets import OxfordPets
|
||||
|
||||
|
||||
template = ['a photo of a {}.']
|
||||
|
||||
|
||||
class SUN397(DatasetBase):
|
||||
|
||||
dataset_dir = 'sun397'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'SUN397')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_SUN397.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
|
||||
def read_data(self, cname2lab, text_file):
|
||||
text_file = os.path.join(self.dataset_dir, text_file)
|
||||
items = []
|
||||
|
||||
with open(text_file, 'r') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
imname = line.strip()[1:] # remove /
|
||||
classname = os.path.dirname(imname)
|
||||
label = cname2lab[classname]
|
||||
impath = os.path.join(self.image_dir, imname)
|
||||
|
||||
names = classname.split('/')[1:] # remove 1st letter
|
||||
names = names[::-1] # put words like indoor/outdoor at first
|
||||
classname = ' '.join(names)
|
||||
|
||||
item = Datum(
|
||||
impath=impath,
|
||||
label=label,
|
||||
classname=classname
|
||||
)
|
||||
items.append(item)
|
||||
|
||||
return items
|
||||
51
datasets/ucf101.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
|
||||
from .utils import Datum, DatasetBase, read_json, write_json, build_data_loader
|
||||
|
||||
from .oxford_pets import OxfordPets
|
||||
|
||||
|
||||
template = ['a photo of a person doing {}.']
|
||||
|
||||
|
||||
class UCF101(DatasetBase):
|
||||
|
||||
dataset_dir = 'ucf101'
|
||||
|
||||
def __init__(self, root, num_shots):
|
||||
self.dataset_dir = os.path.join(root, self.dataset_dir)
|
||||
self.image_dir = os.path.join(self.dataset_dir, 'UCF-101-midframes')
|
||||
self.split_path = os.path.join(self.dataset_dir, 'split_zhou_UCF101.json')
|
||||
|
||||
self.template = template
|
||||
|
||||
train, val, test = OxfordPets.read_split(self.split_path, self.image_dir)
|
||||
train = self.generate_fewshot_dataset(train, num_shots=num_shots)
|
||||
|
||||
super().__init__(train_x=train, val=val, test=test)
|
||||
|
||||
def read_data(self, cname2lab, text_file):
|
||||
text_file = os.path.join(self.dataset_dir, text_file)
|
||||
items = []
|
||||
|
||||
with open(text_file, 'r') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line = line.strip().split(' ')[0] # trainlist: filename, label
|
||||
action, filename = line.split('/')
|
||||
label = cname2lab[action]
|
||||
|
||||
elements = re.findall('[A-Z][^A-Z]*', action)
|
||||
renamed_action = '_'.join(elements)
|
||||
|
||||
filename = filename.replace('.avi', '.jpg')
|
||||
impath = os.path.join(self.image_dir, renamed_action, filename)
|
||||
|
||||
item = Datum(
|
||||
impath=impath,
|
||||
label=label,
|
||||
classname=renamed_action
|
||||
)
|
||||
items.append(item)
|
||||
|
||||
return items
|
||||
377
datasets/utils.py
Normal file
@@ -0,0 +1,377 @@
|
||||
import os
|
||||
import random
|
||||
import os.path as osp
|
||||
import tarfile
|
||||
import zipfile
|
||||
from collections import defaultdict
|
||||
import gdown
|
||||
import json
|
||||
import torch
|
||||
from torch.utils.data import Dataset as TorchDataset
|
||||
import torchvision.transforms as T
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def read_json(fpath):
|
||||
"""Read json file from a path."""
|
||||
with open(fpath, 'r') as f:
|
||||
obj = json.load(f)
|
||||
return obj
|
||||
|
||||
|
||||
def write_json(obj, fpath):
|
||||
"""Writes to a json file."""
|
||||
if not osp.exists(osp.dirname(fpath)):
|
||||
os.makedirs(osp.dirname(fpath))
|
||||
with open(fpath, 'w') as f:
|
||||
json.dump(obj, f, indent=4, separators=(',', ': '))
|
||||
|
||||
|
||||
def read_image(path):
|
||||
"""Read image from path using ``PIL.Image``.
|
||||
|
||||
Args:
|
||||
path (str): path to an image.
|
||||
|
||||
Returns:
|
||||
PIL image
|
||||
"""
|
||||
if not osp.exists(path):
|
||||
raise IOError('No file exists at {}'.format(path))
|
||||
|
||||
while True:
|
||||
try:
|
||||
img = Image.open(path).convert('RGB')
|
||||
return img
|
||||
except IOError:
|
||||
print(
|
||||
'Cannot read image from {}, '
|
||||
'probably due to heavy IO. Will re-try'.format(path)
|
||||
)
|
||||
|
||||
|
||||
def listdir_nohidden(path, sort=False):
|
||||
"""List non-hidden items in a directory.
|
||||
|
||||
Args:
|
||||
path (str): directory path.
|
||||
sort (bool): sort the items.
|
||||
"""
|
||||
items = [f for f in os.listdir(path) if not f.startswith('.') and 'sh' not in f]
|
||||
if sort:
|
||||
items.sort()
|
||||
return items
|
||||
|
||||
|
||||
class Datum:
|
||||
"""Data instance which defines the basic attributes.
|
||||
|
||||
Args:
|
||||
impath (str): image path.
|
||||
label (int): class label.
|
||||
domain (int): domain label.
|
||||
classname (str): class name.
|
||||
"""
|
||||
|
||||
def __init__(self, impath='', label=0, domain=-1, classname=''):
|
||||
assert isinstance(impath, str)
|
||||
assert isinstance(label, int)
|
||||
assert isinstance(domain, int)
|
||||
assert isinstance(classname, str)
|
||||
|
||||
self._impath = impath
|
||||
self._label = label
|
||||
self._domain = domain
|
||||
self._classname = classname
|
||||
|
||||
@property
|
||||
def impath(self):
|
||||
return self._impath
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
return self._label
|
||||
|
||||
@property
|
||||
def domain(self):
|
||||
return self._domain
|
||||
|
||||
@property
|
||||
def classname(self):
|
||||
return self._classname
|
||||
|
||||
|
||||
class DatasetBase:
|
||||
"""A unified dataset class for
|
||||
1) domain adaptation
|
||||
2) domain generalization
|
||||
3) semi-supervised learning
|
||||
"""
|
||||
dataset_dir = '' # the directory where the dataset is stored
|
||||
domains = [] # string names of all domains
|
||||
|
||||
def __init__(self, train_x=None, train_u=None, val=None, test=None,t_sne=None):
|
||||
self._train_x = train_x # labeled training data
|
||||
self._train_u = train_u # unlabeled training data (optional)
|
||||
self._val = val # validation data (optional)
|
||||
self._test = test # test data
|
||||
self._num_classes = self.get_num_classes(train_x)
|
||||
self._lab2cname, self._classnames = self.get_lab2cname(train_x)
|
||||
|
||||
@property
|
||||
def train_x(self):
|
||||
return self._train_x
|
||||
|
||||
@property
|
||||
def train_u(self):
|
||||
return self._train_u
|
||||
|
||||
@property
|
||||
def val(self):
|
||||
return self._val
|
||||
|
||||
@property
|
||||
def test(self):
|
||||
return self._test
|
||||
|
||||
@property
|
||||
def lab2cname(self):
|
||||
return self._lab2cname
|
||||
|
||||
@property
|
||||
def classnames(self):
|
||||
return self._classnames
|
||||
|
||||
@property
|
||||
def num_classes(self):
|
||||
return self._num_classes
|
||||
|
||||
def get_num_classes(self, data_source):
|
||||
"""Count number of classes.
|
||||
|
||||
Args:
|
||||
data_source (list): a list of Datum objects.
|
||||
"""
|
||||
label_set = set()
|
||||
for item in data_source:
|
||||
label_set.add(item.label)
|
||||
return max(label_set) + 1
|
||||
|
||||
def get_lab2cname(self, data_source):
|
||||
"""Get a label-to-classname mapping (dict).
|
||||
|
||||
Args:
|
||||
data_source (list): a list of Datum objects.
|
||||
"""
|
||||
container = set()
|
||||
for item in data_source:
|
||||
container.add((item.label, item.classname))
|
||||
mapping = {label: classname for label, classname in container}
|
||||
labels = list(mapping.keys())
|
||||
labels.sort()
|
||||
classnames = [mapping[label] for label in labels]
|
||||
return mapping, classnames
|
||||
|
||||
def check_input_domains(self, source_domains, target_domains):
|
||||
self.is_input_domain_valid(source_domains)
|
||||
self.is_input_domain_valid(target_domains)
|
||||
|
||||
def is_input_domain_valid(self, input_domains):
|
||||
for domain in input_domains:
|
||||
if domain not in self.domains:
|
||||
raise ValueError(
|
||||
'Input domain must belong to {}, '
|
||||
'but got [{}]'.format(self.domains, domain)
|
||||
)
|
||||
|
||||
def download_data(self, url, dst, from_gdrive=True):
|
||||
if not osp.exists(osp.dirname(dst)):
|
||||
os.makedirs(osp.dirname(dst))
|
||||
|
||||
if from_gdrive:
|
||||
gdown.download(url, dst, quiet=False)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
print('Extracting file ...')
|
||||
|
||||
try:
|
||||
tar = tarfile.open(dst)
|
||||
tar.extractall(path=osp.dirname(dst))
|
||||
tar.close()
|
||||
except:
|
||||
zip_ref = zipfile.ZipFile(dst, 'r')
|
||||
zip_ref.extractall(osp.dirname(dst))
|
||||
zip_ref.close()
|
||||
|
||||
print('File extracted to {}'.format(osp.dirname(dst)))
|
||||
|
||||
def generate_fewshot_dataset(
|
||||
self, *data_sources, num_shots=-1, repeat=True
|
||||
):
|
||||
"""Generate a few-shot dataset (typically for the training set).
|
||||
|
||||
This function is useful when one wants to evaluate a model
|
||||
in a few-shot learning setting where each class only contains
|
||||
a few number of images.
|
||||
|
||||
Args:
|
||||
data_sources: each individual is a list containing Datum objects.
|
||||
num_shots (int): number of instances per class to sample.
|
||||
repeat (bool): repeat images if needed.
|
||||
"""
|
||||
if num_shots < 1:
|
||||
if len(data_sources) == 1:
|
||||
return data_sources[0]
|
||||
return data_sources
|
||||
|
||||
print(f'Creating a {num_shots}-shot dataset')
|
||||
|
||||
output = []
|
||||
|
||||
for data_source in data_sources:
|
||||
tracker = self.split_dataset_by_label(data_source)
|
||||
dataset = []
|
||||
|
||||
for label, items in tracker.items():
|
||||
if len(items) >= num_shots:
|
||||
sampled_items = random.sample(items, num_shots)
|
||||
else:
|
||||
if repeat:
|
||||
sampled_items = random.choices(items, k=num_shots)
|
||||
else:
|
||||
sampled_items = items
|
||||
dataset.extend(sampled_items)
|
||||
|
||||
output.append(dataset)
|
||||
|
||||
if len(output) == 1:
|
||||
return output[0]
|
||||
|
||||
return output
|
||||
|
||||
def split_dataset_by_label(self, data_source):
|
||||
"""Split a dataset, i.e. a list of Datum objects,
|
||||
into class-specific groups stored in a dictionary.
|
||||
|
||||
Args:
|
||||
data_source (list): a list of Datum objects.
|
||||
"""
|
||||
output = defaultdict(list)
|
||||
|
||||
for item in data_source:
|
||||
output[item.label].append(item)
|
||||
|
||||
return output
|
||||
|
||||
def split_dataset_by_domain(self, data_source):
|
||||
"""Split a dataset, i.e. a list of Datum objects,
|
||||
into domain-specific groups stored in a dictionary.
|
||||
|
||||
Args:
|
||||
data_source (list): a list of Datum objects.
|
||||
"""
|
||||
output = defaultdict(list)
|
||||
|
||||
for item in data_source:
|
||||
output[item.domain].append(item)
|
||||
|
||||
return output
|
||||
|
||||
|
||||
class DatasetWrapper(TorchDataset):
|
||||
def __init__(self, data_source, input_size, transform=None, is_train=False,
|
||||
return_img0=False, k_tfm=1):
|
||||
self.data_source = data_source
|
||||
self.transform = transform # accept list (tuple) as input
|
||||
self.is_train = is_train
|
||||
# Augmenting an image K>1 times is only allowed during training
|
||||
self.k_tfm = k_tfm if is_train else 1
|
||||
self.return_img0 = return_img0
|
||||
|
||||
if self.k_tfm > 1 and transform is None:
|
||||
raise ValueError(
|
||||
'Cannot augment the image {} times '
|
||||
'because transform is None'.format(self.k_tfm)
|
||||
)
|
||||
|
||||
# Build transform that doesn't apply any data augmentation
|
||||
interp_mode = T.InterpolationMode.BICUBIC
|
||||
to_tensor = []
|
||||
to_tensor += [T.Resize(input_size, interpolation=interp_mode)]
|
||||
to_tensor += [T.ToTensor()]
|
||||
normalize = T.Normalize(
|
||||
mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711)
|
||||
)
|
||||
to_tensor += [normalize]
|
||||
self.to_tensor = T.Compose(to_tensor)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.data_source)
|
||||
|
||||
def __getitem__(self, idx):
|
||||
item = self.data_source[idx]
|
||||
|
||||
output = {
|
||||
'label': item.label,
|
||||
'domain': item.domain,
|
||||
'impath': item.impath
|
||||
}
|
||||
|
||||
img0 = read_image(item.impath)
|
||||
|
||||
if self.transform is not None:
|
||||
if isinstance(self.transform, (list, tuple)):
|
||||
for i, tfm in enumerate(self.transform):
|
||||
img = self._transform_image(tfm, img0)
|
||||
keyname = 'img'
|
||||
if (i + 1) > 1:
|
||||
keyname += str(i + 1)
|
||||
output[keyname] = img
|
||||
else:
|
||||
img = self._transform_image(self.transform, img0)
|
||||
output['img'] = img
|
||||
|
||||
if self.return_img0:
|
||||
output['img0'] = self.to_tensor(img0)
|
||||
|
||||
return output['img'], output['label'], output['impath']
|
||||
|
||||
def _transform_image(self, tfm, img0):
|
||||
img_list = []
|
||||
|
||||
for k in range(self.k_tfm):
|
||||
img_list.append(tfm(img0))
|
||||
|
||||
img = img_list
|
||||
if len(img) == 1:
|
||||
img = img[0]
|
||||
|
||||
return img
|
||||
|
||||
|
||||
def build_data_loader(
|
||||
data_source=None,
|
||||
batch_size=64,
|
||||
input_size=224,
|
||||
tfm=None,
|
||||
is_train=True,
|
||||
shuffle=False,
|
||||
dataset_wrapper=None
|
||||
):
|
||||
|
||||
if dataset_wrapper is None:
|
||||
dataset_wrapper = DatasetWrapper
|
||||
|
||||
# Build data loader
|
||||
data_loader = torch.utils.data.DataLoader(
|
||||
dataset_wrapper(data_source, input_size=input_size, transform=tfm, is_train=is_train),
|
||||
batch_size=batch_size,
|
||||
num_workers=8,
|
||||
shuffle=shuffle,
|
||||
drop_last=False,
|
||||
pin_memory=(torch.cuda.is_available())
|
||||
)
|
||||
assert len(data_loader) > 0
|
||||
|
||||
return data_loader
|
||||
0
engine/__init__.py
Normal file
424
engine/partial_model.py
Normal file
@@ -0,0 +1,424 @@
|
||||
import torch
|
||||
from torch import nn
|
||||
|
||||
|
||||
#clip文本编码器前半
|
||||
class TransformerEncoder(nn.Module):
|
||||
def __init__(self, dtype,
|
||||
token_embedding,
|
||||
positional_embedding=None,
|
||||
transformer_encoder=None,
|
||||
ln_final=None,
|
||||
text_projection=None):
|
||||
super().__init__()
|
||||
self.dtype = dtype
|
||||
self.token_embedding = token_embedding
|
||||
self.positional_embedding = positional_embedding
|
||||
self.transformer_encoder = transformer_encoder
|
||||
self.ln_final = ln_final
|
||||
self.text_projection = text_projection
|
||||
if self.positional_embedding is None:
|
||||
assert self.transformer_encoder is None
|
||||
if self.transformer_encoder is None:
|
||||
assert self.ln_final is None
|
||||
if self.ln_final is None:
|
||||
assert self.text_projection is None
|
||||
|
||||
def forward(self, text):
|
||||
x = self.token_embedding(text).type(self.dtype) # (bs, seq_len, dim)
|
||||
eot_indices = text.argmax(dim=-1)
|
||||
if self.positional_embedding is not None:
|
||||
x = x + self.positional_embedding.type(self.dtype)
|
||||
|
||||
if self.transformer_encoder is not None:
|
||||
x = x.permute(1, 0, 2) # NLD -> LND
|
||||
x = self.transformer_encoder(x)
|
||||
x = x.permute(1, 0, 2) # LND -> NLD
|
||||
|
||||
if self.ln_final is not None:
|
||||
x = self.ln_final(x).type(self.dtype)
|
||||
|
||||
if self.text_projection is not None:
|
||||
x = x[torch.arange(x.shape[0]), eot_indices] @ self.text_projection
|
||||
return x, eot_indices
|
||||
|
||||
#clip文本编码器后半
|
||||
class PartialTransformer(nn.Module):
|
||||
def __init__(self, dtype,
|
||||
logit_scale,
|
||||
vocab_size,
|
||||
positional_embedding=None,
|
||||
partial_transformer=None,
|
||||
ln_final=None,
|
||||
text_projection=None):
|
||||
super().__init__()
|
||||
self.dtype = dtype
|
||||
self.logit_scale = logit_scale
|
||||
self.vocab_size = vocab_size
|
||||
self.positional_embedding = positional_embedding
|
||||
self.partial_transformer = partial_transformer
|
||||
self.ln_final = ln_final
|
||||
self.text_projection = text_projection
|
||||
if self.positional_embedding is not None:
|
||||
assert self.partial_transformer is not None
|
||||
assert self.ln_final is not None
|
||||
assert self.text_projection is not None
|
||||
elif self.partial_transformer is not None:
|
||||
assert self.ln_final is not None
|
||||
assert self.text_projection is not None
|
||||
elif self.ln_final is not None:
|
||||
assert self.text_projection is not None
|
||||
|
||||
def forward(self, x, eot_indices):
|
||||
if self.positional_embedding is not None:
|
||||
x = x + self.positional_embedding.type(self.dtype)
|
||||
|
||||
if self.partial_transformer is not None:
|
||||
x = x.permute(1, 0, 2)
|
||||
x = self.partial_transformer(x)
|
||||
x = x.permute(1, 0, 2)
|
||||
|
||||
if self.ln_final is not None:
|
||||
x = self.ln_final(x).type(self.dtype)
|
||||
x = x[torch.arange(x.shape[0]), eot_indices] @ self.text_projection
|
||||
return x
|
||||
|
||||
#返回前后两个文本编码器
|
||||
def get_text(clip_model, text_layer_idx=0):
|
||||
# contains feature_extractor (does encode_text() from prompts) and partial_model (need to reverse the dim)
|
||||
vocab_size = clip_model.vocab_size
|
||||
token_embedding = clip_model.token_embedding
|
||||
positional_embedding = clip_model.positional_embedding
|
||||
transformer = clip_model.transformer
|
||||
ln_final = clip_model.ln_final
|
||||
text_projection = clip_model.text_projection
|
||||
logit_scale = clip_model.logit_scale
|
||||
dtype = clip_model.dtype
|
||||
|
||||
if text_layer_idx == -1:
|
||||
# finetune all layers
|
||||
feature_extractor = TransformerEncoder(
|
||||
dtype, token_embedding)
|
||||
partial_model = PartialTransformer(
|
||||
dtype, logit_scale, vocab_size,
|
||||
positional_embedding=positional_embedding,
|
||||
partial_transformer=transformer,
|
||||
ln_final=ln_final, text_projection=text_projection)
|
||||
elif text_layer_idx == 0:
|
||||
# finetune no layers
|
||||
feature_extractor = TransformerEncoder(
|
||||
dtype, token_embedding,
|
||||
positional_embedding=positional_embedding, transformer_encoder=transformer,
|
||||
ln_final=ln_final, text_projection=text_projection)
|
||||
partial_model = PartialTransformer(dtype, logit_scale, vocab_size)
|
||||
else:
|
||||
# finetune some layers
|
||||
transformer_encoder = transformer.resblocks[:-text_layer_idx]
|
||||
partial_transformer = transformer.resblocks[-text_layer_idx:]
|
||||
feature_extractor = TransformerEncoder(
|
||||
dtype, token_embedding,
|
||||
positional_embedding=positional_embedding,
|
||||
transformer_encoder=transformer_encoder)
|
||||
partial_model = PartialTransformer(
|
||||
dtype, logit_scale, vocab_size,
|
||||
positional_embedding=None,
|
||||
partial_transformer=partial_transformer,
|
||||
ln_final=ln_final, text_projection=text_projection)
|
||||
return feature_extractor, partial_model
|
||||
|
||||
#RN50图像编码器分段
|
||||
class PartialResNet(nn.Module):
|
||||
def __init__(self, conv1=None,
|
||||
bn1=None,
|
||||
conv2=None,
|
||||
bn2=None,
|
||||
conv3=None,
|
||||
bn3=None,
|
||||
layer1=None,
|
||||
layer2=None,
|
||||
layer3=None,
|
||||
layer4=None,
|
||||
attnpool=None,
|
||||
mode='feature_extractor'):
|
||||
super().__init__()
|
||||
assert mode in ['feature_extractor', 'partial_model']
|
||||
self.conv1 = conv1
|
||||
self.bn1 = bn1
|
||||
self.conv2 = conv2
|
||||
self.bn2 = bn2
|
||||
self.conv3 = conv3
|
||||
self.bn3 = bn3
|
||||
self.relu = nn.ReLU(inplace=True)
|
||||
self.avgpool = nn.AvgPool2d(2)
|
||||
self.layer1 = layer1
|
||||
self.layer2 = layer2
|
||||
self.layer3 = layer3
|
||||
self.layer4 = layer4
|
||||
self.attnpool = attnpool
|
||||
self.apply_stem = self.conv3 != None
|
||||
if mode == 'partial_model':
|
||||
if self.conv1 is not None:
|
||||
assert self.bn1 is not None
|
||||
if self.bn1 is not None:
|
||||
assert self.conv2 is not None
|
||||
if self.conv2 is not None:
|
||||
assert self.bn2 is not None
|
||||
if self.bn2 is not None:
|
||||
assert self.conv3 is not None
|
||||
if self.conv3 is not None:
|
||||
assert self.conv1 is not None # make sure entire stem is included
|
||||
assert self.bn3 is not None
|
||||
if self.bn3 is not None:
|
||||
assert self.layer1 is not None
|
||||
if self.layer1 is not None:
|
||||
assert self.layer2 is not None
|
||||
if self.layer2 is not None:
|
||||
assert self.layer3 is not None
|
||||
if self.layer3 is not None:
|
||||
assert self.layer4 is not None
|
||||
if self.layer4 is not None:
|
||||
assert self.attnpool is not None
|
||||
elif mode == 'feature_extractor':
|
||||
if self.attnpool is not None:
|
||||
assert self.layer4 is not None
|
||||
if self.layer4 is not None:
|
||||
assert self.layer3 is not None
|
||||
if self.layer3 is not None:
|
||||
assert self.layer2 is not None
|
||||
if self.layer2 is not None:
|
||||
assert self.layer1 is not None
|
||||
if self.layer1 is not None:
|
||||
assert self.bn3 is not None
|
||||
if self.bn3 is not None:
|
||||
assert self.conv3 is not None
|
||||
if self.conv3 is not None:
|
||||
assert self.bn2 is not None
|
||||
if self.bn2 is not None:
|
||||
assert self.conv2 is not None
|
||||
if self.conv2 is not None:
|
||||
assert self.bn1 is not None
|
||||
if self.bn1 is not None:
|
||||
assert self.conv1 is not None
|
||||
|
||||
def forward(self, x):
|
||||
if self.apply_stem:
|
||||
def stem(x):
|
||||
for conv, bn in [(self.conv1, self.bn1), (self.conv2, self.bn2), (self.conv3, self.bn3)]:
|
||||
x = self.relu(bn(conv(x)))
|
||||
x = self.avgpool(x)
|
||||
return x
|
||||
x = x.type(self.conv1.weight.dtype)
|
||||
x = stem(x)
|
||||
if self.layer1 is not None:
|
||||
x = self.layer1(x)
|
||||
if self.layer2 is not None:
|
||||
x = self.layer2(x)
|
||||
if self.layer3 is not None:
|
||||
x = self.layer3(x)
|
||||
if self.layer4 is not None:
|
||||
x = self.layer4(x)
|
||||
if self.attnpool is not None:
|
||||
x = self.attnpool(x)
|
||||
return x
|
||||
|
||||
#返回前后两个RN50图像编码器
|
||||
def get_image_resnet(model, image_layer_idx=0):
|
||||
# contains feature_extractor and partial_model
|
||||
# the 3-layer stem
|
||||
conv1 = model.conv1
|
||||
bn1 = model.bn1
|
||||
conv2 = model.conv2
|
||||
bn2 = model.bn2
|
||||
conv3 = model.conv3
|
||||
bn3 = model.bn3
|
||||
avgpool = model.avgpool
|
||||
relu = model.relu
|
||||
|
||||
layer1 = model.layer1
|
||||
layer2 = model.layer2
|
||||
layer3 = model.layer3
|
||||
layer4 = model.layer4
|
||||
|
||||
attnpool = model.attnpool
|
||||
|
||||
if image_layer_idx == -1:
|
||||
# finetune all layers
|
||||
feature_extractor = PartialResNet(mode='feature_extractor')
|
||||
partial_model = PartialResNet(conv1=conv1,
|
||||
bn1=bn1,
|
||||
conv2=conv2,
|
||||
bn2=bn2,
|
||||
conv3=conv3,
|
||||
bn3=bn3,
|
||||
layer1=layer1,
|
||||
layer2=layer2,
|
||||
layer3=layer3,
|
||||
layer4=layer4,
|
||||
attnpool=attnpool,
|
||||
mode='partial_model')
|
||||
elif image_layer_idx == 0:
|
||||
# finetune no layers
|
||||
feature_extractor = PartialResNet(conv1=conv1,
|
||||
bn1=bn1,
|
||||
conv2=conv2,
|
||||
bn2=bn2,
|
||||
conv3=conv3,
|
||||
bn3=bn3,
|
||||
layer1=layer1,
|
||||
layer2=layer2,
|
||||
layer3=layer3,
|
||||
layer4=layer4,
|
||||
attnpool=attnpool,
|
||||
mode='feature_extractor')
|
||||
partial_model = PartialResNet(mode='partial_model')
|
||||
elif image_layer_idx == 1:
|
||||
# finetune attention pool
|
||||
feature_extractor = PartialResNet(conv1=conv1,
|
||||
bn1=bn1,
|
||||
conv2=conv2,
|
||||
bn2=bn2,
|
||||
conv3=conv3,
|
||||
bn3=bn3,
|
||||
layer1=layer1,
|
||||
layer2=layer2,
|
||||
layer3=layer3,
|
||||
layer4=layer4,
|
||||
mode='feature_extractor')
|
||||
partial_model = PartialResNet(attnpool=attnpool,
|
||||
mode='partial_model')
|
||||
elif image_layer_idx == 2:
|
||||
# finetune attnpool and layer4
|
||||
feature_extractor = PartialResNet(conv1=conv1,
|
||||
bn1=bn1,
|
||||
conv2=conv2,
|
||||
bn2=bn2,
|
||||
conv3=conv3,
|
||||
bn3=bn3,
|
||||
layer1=layer1,
|
||||
layer2=layer2,
|
||||
layer3=layer3,
|
||||
mode='feature_extractor')
|
||||
partial_model = PartialResNet(layer4=layer4,
|
||||
attnpool=attnpool,
|
||||
mode='partial_model')
|
||||
else:
|
||||
raise ValueError("Invalid layer index")
|
||||
|
||||
return feature_extractor, partial_model
|
||||
|
||||
#vit16图像编码器
|
||||
class PartialViT(nn.Module):
|
||||
def __init__(self, conv1=None,
|
||||
class_embedding=None,
|
||||
positional_embedding=None,
|
||||
ln_pre=None,
|
||||
transformer_encoder=None,
|
||||
ln_post=None,
|
||||
proj=None,
|
||||
mode='feature_extractor'):
|
||||
super().__init__()
|
||||
assert mode in ['feature_extractor', 'partial_model']
|
||||
self.conv1 = conv1
|
||||
self.class_embedding = class_embedding
|
||||
self.positional_embedding = positional_embedding
|
||||
self.ln_pre = ln_pre
|
||||
self.transformer_encoder = transformer_encoder
|
||||
self.ln_post = ln_post
|
||||
self.proj = proj
|
||||
if mode == 'partial_model':
|
||||
if self.conv1 is not None:
|
||||
assert self.ln_pre is not None
|
||||
if self.ln_pre is not None:
|
||||
assert self.transformer_encoder is not None
|
||||
if self.transformer_encoder is not None:
|
||||
assert self.ln_post is not None
|
||||
if self.ln_post is not None:
|
||||
assert self.proj is not None
|
||||
elif mode == 'feature_extractor':
|
||||
if self.proj is not None:
|
||||
assert self.ln_post is not None
|
||||
if self.ln_post is not None:
|
||||
assert self.transformer_encoder is not None
|
||||
if self.transformer_encoder is not None:
|
||||
assert self.ln_pre is not None
|
||||
if self.ln_pre is not None:
|
||||
assert self.conv1 is not None
|
||||
|
||||
def forward(self, x):
|
||||
if self.conv1 is not None:
|
||||
x = self.conv1(x)
|
||||
x = x.reshape(x.shape[0], x.shape[1], -1) # shape = [*, width, grid ** 2]
|
||||
x = x.permute(0, 2, 1) # shape = [*, grid ** 2, width]
|
||||
|
||||
if self.class_embedding is not None:
|
||||
x = torch.cat([self.class_embedding.to(x.dtype) + torch.zeros(x.shape[0], 1, x.shape[-1], dtype=x.dtype,
|
||||
device=x.device), x],
|
||||
dim=1) # shape = [*, grid ** 2 + 1, width]
|
||||
|
||||
if self.positional_embedding is not None:
|
||||
x = x + self.positional_embedding.to(x.dtype)
|
||||
|
||||
if self.ln_pre is not None:
|
||||
x = self.ln_pre(x)
|
||||
|
||||
if self.transformer_encoder is not None:
|
||||
x = x.permute(1, 0, 2) # NLD -> LND
|
||||
x = self.transformer_encoder(x)
|
||||
x = x.permute(1, 0, 2) # LND -> NLD
|
||||
|
||||
if self.ln_post is not None:
|
||||
x = self.ln_post(x[:, 0, :])
|
||||
|
||||
if self.proj is not None:
|
||||
x = x @ self.proj
|
||||
|
||||
return x
|
||||
|
||||
#返回前后两个vit16图像编码器
|
||||
def get_image_vit(model, image_layer_idx=0):
|
||||
# contains feature_extractor and partial_model
|
||||
conv1 = model.conv1
|
||||
class_embedding = model.class_embedding
|
||||
positional_embedding = model.positional_embedding
|
||||
ln_pre = model.ln_pre
|
||||
transformer = model.transformer
|
||||
ln_post = model.ln_post
|
||||
proj = model.proj
|
||||
|
||||
if image_layer_idx == -1:
|
||||
# finetune all layers
|
||||
feature_extractor = PartialViT(mode='feature_extractor')
|
||||
partial_model = PartialViT(conv1=conv1,
|
||||
class_embedding=class_embedding,
|
||||
positional_embedding=positional_embedding,
|
||||
ln_pre=ln_pre,
|
||||
transformer_encoder=transformer,
|
||||
ln_post=ln_post,
|
||||
proj=proj,
|
||||
mode='partial_model')
|
||||
elif image_layer_idx == 0:
|
||||
# finetune no layers
|
||||
feature_extractor = PartialViT(conv1=conv1,
|
||||
class_embedding=class_embedding,
|
||||
positional_embedding=positional_embedding,
|
||||
ln_pre=ln_pre,
|
||||
transformer_encoder=transformer,
|
||||
ln_post=ln_post,
|
||||
proj=proj,
|
||||
mode='feature_extractor')
|
||||
partial_model = PartialViT(mode='partial_model')
|
||||
else:
|
||||
# finetune some layers
|
||||
transformer_encoder = transformer.resblocks[:-image_layer_idx]
|
||||
partial_transformer = transformer.resblocks[-image_layer_idx:]
|
||||
feature_extractor = PartialViT(conv1=conv1,
|
||||
class_embedding=class_embedding,
|
||||
positional_embedding=positional_embedding,
|
||||
ln_pre=ln_pre,
|
||||
transformer_encoder=transformer_encoder,
|
||||
mode='feature_extractor')
|
||||
partial_model = PartialViT(transformer_encoder=partial_transformer,
|
||||
ln_post=ln_post,
|
||||
proj=proj,
|
||||
mode='partial_model')
|
||||
return feature_extractor, partial_model
|
||||
605
gc-clip_make_pic.py
Normal file
@@ -0,0 +1,605 @@
|
||||
import matplotlib
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
# matplotlib画图中中文显示会有问题,需要这两行设置默认字体.没中文可以去掉
|
||||
plt.rcParams['font.sans-serif']=['SimHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
|
||||
# 设置figure_size尺寸
|
||||
# plt.rcParams['figure.figsize'] = (22.0, 22.0)
|
||||
plt.rcParams['figure.figsize'] = (5.0,5.0)
|
||||
fig = plt.figure()
|
||||
|
||||
# 设定图表颜色
|
||||
fig.set(alpha=0.2)
|
||||
#fig.suptitle('suptitle', fontsize=24, x=0.6,y=0.9, horizontalalignment='left', va='bottom')
|
||||
|
||||
# 输入数据
|
||||
# plt.subplot2grid((4,3),(0,0))
|
||||
#Average over 11 datasets
|
||||
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
|
||||
# GC_CLIP=[65.67090909,68.98363636,72.51636364,75.58,78.20090909]
|
||||
#
|
||||
# # GPT_CLIP=[65.54,68.59,72.23,75.31,77.94]
|
||||
#
|
||||
# DA_CLIP=[65.27,68.20,72.01,75.21,77.70]
|
||||
#
|
||||
#
|
||||
# y_tip_adapter=[62.3282,64.6182,66.5327,68.4955,70.3182]
|
||||
#
|
||||
# y_tip_adapter_f=[63.2982,65.93913,68.9836,72.1573,75.1346]
|
||||
#
|
||||
# y_clip_adapter=[62.6745,65.5527,68.6055,71.3964,74.4436]
|
||||
#
|
||||
# y_imagenet_CoOp=[59.5882,62.3236,66.7664,69.8918,73.4251]
|
||||
# y_clip=[58.9627]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
# #
|
||||
# # #数据及线属性
|
||||
# # #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# # #
|
||||
# # #
|
||||
# # #
|
||||
# # #
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('Average over 11 datasets',fontproperties='Times New Roman', fontsize=15,fontweight='bold')
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("Average.png", dpi=600)
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
#
|
||||
#
|
||||
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(0,1))
|
||||
|
||||
# GC_CLIP=[90.3,90.82,92.45,92.77,94.22]
|
||||
# # GPT_CLIP=[89.73,90.54,92.26,92.57,93.96]
|
||||
# DA_CLIP=[89.45,90.34,91.89,92.09,93.79]
|
||||
#
|
||||
# y_tip_adapter=[87.18,88.44,89.39,89.83,90.18]
|
||||
# y_tip_adapter_f=[87.9,89.4,90.78,91.1,92.28]
|
||||
# y_imagenet_CoOp=[87.53,87.93,89.55,90.21,91.83]
|
||||
# y_clip_adapter=[88.6,89.37,89.98,91.4,92.49]
|
||||
#
|
||||
# y_clip=[86.29]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('Caltech101',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("Caltech101.png", dpi=600)
|
||||
#
|
||||
#
|
||||
# #
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(0,2))
|
||||
# #
|
||||
# GC_CLIP=[50.73,56.51,62.2,66.76,69.71]
|
||||
#
|
||||
# # GPT_CLIP=[50.52,56.21,61.92,66.58,69.31]
|
||||
#
|
||||
# DA_CLIP=[46.28,52.19,61.76,66.19,68.79]
|
||||
#
|
||||
# y_tip_adapter=[46.22,49.47,53.96,58.63,60.93]
|
||||
#
|
||||
# y_tip_adapter_f=[48.58,51.64,57.21,61.92,66.23]
|
||||
#
|
||||
# y_imagenet_CoOp=[44.39,45.15,53.49,59.97,63.58]
|
||||
#
|
||||
# y_clip_adapter=[45.8,51.48,56.86,61,65.96]
|
||||
#
|
||||
# y_clip=[42.32]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('DTD',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("DTD.png", dpi=600)
|
||||
# #
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# # 输入数据
|
||||
# # plt.subplot2grid((4,3),(1,0))
|
||||
# # #EuroSAT
|
||||
# GC_CLIP=[58.85,67.38,78.54,84.84,84.90]
|
||||
#
|
||||
# # GPT_CLIP=[58.46,66.96,78.34,84.24,84.44]
|
||||
#
|
||||
# DA_CLIP=[57.41,66.41,77.95,83.90,84.17]
|
||||
#
|
||||
# y_tip_adapter=[54.38,61.68,65.32,67.95,70.54]
|
||||
#
|
||||
# y_tip_adapter_f=[51.81,66.32,69.23,77.69,81.96]
|
||||
#
|
||||
# y_clip_adapter=[61.4,63.9,73.38,77.93,84.43]
|
||||
#
|
||||
# y_imagenet_CoOp=[50.63,61.5,70.18,76.73,83.53]
|
||||
#
|
||||
# y_clip=[37.56]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('EuroSAT',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("EuroSAT.png", dpi=600)
|
||||
# #
|
||||
# #
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(1,1))
|
||||
# #FGVCAircraft
|
||||
# GC_CLIP=[22.92,24.82,28.68,34.88,42.66]
|
||||
#
|
||||
# # GPT_CLIP=[22.70,24.62,28.18,34.59,42.30]
|
||||
#
|
||||
# DA_CLIP=[22.53,24.48,28.08,34.26,41.34]
|
||||
#
|
||||
# y_tip_adapter=[19.05,21.2,22.41,25.59,29.76]
|
||||
#
|
||||
# y_tip_adapter_f=[20.06,21.17,24.97,28.13,34.83]
|
||||
#
|
||||
# y_imagenet_CoOp=[9.64,18.68,21.87,26.13,31.26]
|
||||
#
|
||||
# y_clip_adapter=[17.49,20.1,22.59,26.25,32.1]
|
||||
#
|
||||
# y_clip=[17.28]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('FGVCAircraft',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("FGVCAircraft.png", dpi=600)
|
||||
# #
|
||||
# #
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(1,2))
|
||||
# #Flowers102
|
||||
# GC_CLIP=[80.88,88.8,93.68,96.20,96.7]
|
||||
#
|
||||
# # GPT_CLIP=[80.76,87.80,93.32,95.67,96.66]
|
||||
#
|
||||
# DA_CLIP=[80.88,87.78,93.26,95.82,96.80]
|
||||
#
|
||||
# y_tip_adapter=[73.12,79.13,83.8,87.98,89.89]
|
||||
#
|
||||
# y_tip_adapter_f=[76.7,79.5,89,92.4,93.9]
|
||||
#
|
||||
# y_imagenet_CoOp=[68.12,77.51,86.2,91.18,94.51]
|
||||
#
|
||||
# y_clip_adapter=[73.49,81.61,87.17,91.72,93.9]
|
||||
#
|
||||
# y_clip=[66.14]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('Flowers102',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("Flowers102.png", dpi=600)
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(2,0))
|
||||
#Food101
|
||||
# GC_CLIP=[78.44,78.67,78.81,78.96,79.72]
|
||||
#
|
||||
# # GPT_CLIP=[78.24,78.56,78.67,78.82,79.59]
|
||||
#
|
||||
# DA_CLIP=[78.17,78.34,78.50,78.55,79.40]
|
||||
#
|
||||
# y_tip_adapter=[77.42,77.52,77.54,77.76,77.83]
|
||||
#
|
||||
# y_tip_adapter_f=[77.27,77.44,77.2,78.36,79.05]
|
||||
#
|
||||
# y_imagenet_CoOp=[74.32,72.49,73.33,71.82,74.67]
|
||||
#
|
||||
# y_clip_adapter=[76.82,77.22,77.92,78.04,78.25]
|
||||
#
|
||||
# y_clip=[77.31]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('Food101',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("Food101.png", dpi=600)
|
||||
# #
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(2,1))
|
||||
# #imagenet
|
||||
# GC_CLIP=[62,63.14,63.52,65.02,66.46]
|
||||
# # GPT_CLIP=[61.82,62.83,63.27,64.72,66.25]
|
||||
# DA_CLIP=[61.41,61.83,62.91,64.54,66.09]
|
||||
#
|
||||
# y_tip_adapter=[60.7,60.96,60.98,61.45,62.03]
|
||||
# y_tip_adapter_f=[61.32,61.69,62.52,64,65.51]
|
||||
# y_clip_adapter=[61.2,61.52,61.84,62.68,63.59]
|
||||
# y_imagenet_CoOp=[57.15,57.81,59.99,61.56,62.95]
|
||||
# y_clip=[60.33]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('ImageNet',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# #plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
#
|
||||
# plt.savefig("ImageNet.png", dpi=600)
|
||||
#
|
||||
#
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(2,2))
|
||||
# #OxfordPets
|
||||
# GC_CLIP=[86.1,87.94,88.74,89.25,90.13]
|
||||
#
|
||||
# # GPT_CLIP=[85.94,86.79,88.63,89.01,89.92]
|
||||
#
|
||||
# DA_CLIP=[85.91,86.75,88.50,88.96,89.86]
|
||||
#
|
||||
# y_tip_adapter=[86.1,87.03,86.45,87.03,88.14]
|
||||
#
|
||||
# y_tip_adapter_f=[86.44,86.44,87,88.11,89.13]
|
||||
# y_imagenet_CoOp=[85.89,82.64,86.7,85.32,87.01]
|
||||
# y_clip_adapter=[85.99,86.73,87.46,87.65,87.84]
|
||||
# y_clip=[85.77]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('OxfordPets',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
#
|
||||
# plt.savefig("OxfordPets.png", dpi=600)
|
||||
|
||||
|
||||
|
||||
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(3,0))
|
||||
# #StanfordCars
|
||||
# GC_CLIP=[60.17,62.57,66.92,73.92,80]
|
||||
#
|
||||
# # GPT_CLIP=[60.13,62.46,66.73,73.81,79.72]
|
||||
#
|
||||
# DA_CLIP=[59.77,62.12,66.30,73.35,79.54]
|
||||
#
|
||||
# y_tip_adapter=[57.54,57.93,61.45,62.93,66.77]
|
||||
#
|
||||
# y_tip_adapter_f=[58.42,61.06,64.54,69.32,75.08]
|
||||
#
|
||||
# y_imagenet_CoOp=[55.59,58.28,62.62,68.43,73.3659]
|
||||
#
|
||||
# y_clip_adapter=[55.13,58.74,62.45,67.89,74.01]
|
||||
#
|
||||
# y_clip=[55.61]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #
|
||||
# # 数据及线属性
|
||||
# # cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('StanfordCars',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# #plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("StanfordCars.png", dpi=600)
|
||||
|
||||
|
||||
|
||||
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(3,1))
|
||||
# #SUN397
|
||||
# GC_CLIP=[64.1,66.34,69.24,70.78,73.21]
|
||||
#
|
||||
# # GPT_CLIP=[63.91,66.23,68.52,70.59,72.98]
|
||||
#
|
||||
# DA_CLIP=[63.42,65.24,68.13,70.10,72.69]
|
||||
#
|
||||
# y_tip_adapter=[61.3,62.7,64.1,65.62,66.85]
|
||||
#
|
||||
# y_tip_adapter_f=[62.4,63.22,65.75,68.28,71.27]
|
||||
# y_imagenet_CoOp=[60.29,59.48,63.47,65.52,69.26]
|
||||
#
|
||||
# y_clip_adapter=[61.3,63.29,65.96,67.5,69.55]
|
||||
#
|
||||
# y_clip=[58.52]
|
||||
# x=[1,2,4,8,16]
|
||||
# x_zero=[0]
|
||||
#
|
||||
# #数据及线属性
|
||||
# #cacfc
|
||||
# plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# # plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
# plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
# plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
# plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
# plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
# plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
# plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
# #clip_adapter
|
||||
#
|
||||
# plt.grid(linestyle="--")
|
||||
# # 修改坐标轴字体及大小
|
||||
# plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
# plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
# #标题设置
|
||||
# plt.title('SUN397',fontproperties='Times New Roman', fontsize=15)
|
||||
# plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
# plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# # plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# # 添加标签
|
||||
# plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
# ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
# plt.savefig("SUN397.png", dpi=600)
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# # 输入数据
|
||||
# plt.subplot2grid((4,3),(3,2))
|
||||
# #UCF101
|
||||
GC_CLIP=[67.86,71.73,75,78.2,82.5]
|
||||
|
||||
# GPT_CLIP=[67.60,71.46,74.72,77.86,82.26]
|
||||
|
||||
DA_CLIP=[67.46,71.27,74.49,77.77,82.08]
|
||||
|
||||
y_tip_adapter=[62.6,64.74,66.46,68.68,70.58]
|
||||
|
||||
y_tip_adapter_f=[65.38,67.45,71.17,74.42,77.24]
|
||||
|
||||
y_imagenet_CoOp=[61.92,64.09,67.03,71.94,75.71]
|
||||
|
||||
y_clip_adapter=[62.2,67.12,69.05,73.3,76.76]
|
||||
|
||||
y_clip=[61.46]
|
||||
x=[1,2,4,8,16]
|
||||
x_zero=[0]
|
||||
|
||||
# 数据及线属性
|
||||
# cacfc
|
||||
plt.plot(x, GC_CLIP, color='r', linestyle='-', marker='*', linewidth=1, label='GC-CLIP')
|
||||
# plt.plot(x, GPT_CLIP, color='#4169E1', linestyle='-', marker='*', linewidth=1, label='GPT-CLIP')
|
||||
plt.plot(x, DA_CLIP, color='g', linestyle='-', marker='*', linewidth=1, label='DA-CLIP')
|
||||
plt.plot(x, y_tip_adapter, color='cyan', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter')
|
||||
plt.plot(x, y_tip_adapter_f, color='orange', linestyle='-', marker='*', linewidth=1, label='Tip-Adapter-F')
|
||||
plt.plot(x, y_clip_adapter, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='CLIP-Adapter')
|
||||
plt.plot(x, y_imagenet_CoOp, color='hotpink', linestyle='-', marker='*', linewidth=1, label='CoOp')
|
||||
plt.plot(x_zero, y_clip, color='mediumpurple', linestyle='-', marker='*', linewidth=1, label='Zero-shot CLIP')
|
||||
#clip_adapter
|
||||
|
||||
plt.grid(linestyle="--")
|
||||
# 修改坐标轴字体及大小
|
||||
plt.yticks(fontproperties='Times New Roman', size=14)#设置大小及加粗
|
||||
plt.xticks(fontproperties='Times New Roman', size=14)
|
||||
#标题设置
|
||||
plt.title('UCF101',fontproperties='Times New Roman', fontsize=15)
|
||||
plt.xlabel('Number of labeled training examples per class',fontproperties='Times New Roman', fontsize=12)
|
||||
plt.ylabel('Score(%)',fontproperties='Times New Roman')
|
||||
# plt.legend(loc='lower right',prop={'family' : 'Times New Roman', 'size': 13})
|
||||
# 添加标签
|
||||
plt.annotate('Zero-shot\n CLIP', xy=(x_zero[0], y_clip[0]), xytext=(x_zero[0]+0.3, y_clip[0]-0.9),
|
||||
ha='center', fontproperties='Times New Roman', fontsize=10, color='mediumpurple')
|
||||
|
||||
plt.savefig("UCF101.png", dpi=600)
|
||||
# plt.show()
|
||||
5202
gpt_file/caltech_prompt.json
Normal file
789
gpt_file/caltech_prompt_chat.json
Normal file
@@ -0,0 +1,789 @@
|
||||
{
|
||||
"face": ["A face typically has two eyes, a nose, a mouth, and two ears. ","The eyes are usually located above the nose and mouth, with the ears on either side of the head. ","The nose is typically in the center of the face, above the mouth."],
|
||||
"leopard": ["SLeopards have a distinctive spotted coat with black spots on a yellow or orange background.",
|
||||
"Leopards have a muscular and agile body that is built for hunting and climbing.",
|
||||
"The spots on their coat are often arranged in a circular shape, known as rosettes.",
|
||||
"Leopards have a large head with powerful jaws.",
|
||||
"Leopards have sharp retractable claws that help them climb trees and catch prey."],
|
||||
"motorbike": [
|
||||
"A motorbike typically has a long, narrow body with two wheels and a seat for the rider. ",
|
||||
"It usually has a gas tank, handlebars, foot pegs or floorboards, and a variety of gauges and controls on the dashboard.",
|
||||
"The front of the bike usually has a headlight and may also have a windshield for protection against wind and debris. ",
|
||||
"The engine is often located between the wheels and is covered by a protective casing.",
|
||||
"The back of the bike may have a passenger seat or a luggage rack, and the wheels may be equipped with disc brakes for stopping power."],
|
||||
"accordion": [
|
||||
"An accordion is a musical instrument with a box-like shape.",
|
||||
"An accordion typically has a rectangular or trapezoidal body that is made of wood, metal, or plastic.",
|
||||
"The body is usually covered with leather or other materials to protect it.",
|
||||
"The accordion has a set of bellows that are used to produce sound.",
|
||||
"The bellows are made of pleated paper or fabric, and are squeezed together and pulled apart to create air pressure that produces sound.",
|
||||
"The accordion also has a set of buttons or keys on the front of the body that are used to play different notes and chords."],
|
||||
"airplane": [
|
||||
"An airplane has a long, streamlined body with wings on either side that provide lift to keep the airplane in the air.",
|
||||
"The wings are usually curved on the top and flat on the bottom, and they have flaps and ailerons that can be adjusted to control the airplane's speed and altitude.",
|
||||
"At the front of the airplane is the cockpit, where the pilots sit and control the aircraft using a variety of instruments and controls.",
|
||||
"The cockpit usually has large windows that provide a clear view of the surrounding airspace.",
|
||||
"The tail of the airplane is made up of a vertical stabilizer and a horizontal stabilizer, which help to keep the airplane stable in flight."
|
||||
],
|
||||
"anchor": [
|
||||
"An anchor is typically made of metal, such as iron or steel.",
|
||||
"It has a heavy weight and a distinctive shape that resembles a cross or a T.",
|
||||
"The main part of the anchor is called the shank, which is the long, straight part of the anchor that connects to the chain or rope.",
|
||||
"At the bottom of the shank is the fluke, which is the pointed part of the anchor that digs into the sea floor to hold the ship in place.",
|
||||
"The anchor may also have arms, called flukes or bills, that are curved and angled to help the anchor set and hold onto the seabed."
|
||||
],
|
||||
"ant": [
|
||||
"Ants are small, typically only a few millimeters in length.",
|
||||
"Ants have six legs and a segmented body with three distinct parts: the head, thorax, and abdomen.",
|
||||
"The head of an ant has two antennae, which are used for sensing their environment and communicating with other ants.",
|
||||
"Ants have two small eyes, called ocelli, on the top of their head that can detect light and movement.",
|
||||
"Depending on the species, ants can range in color from black, brown, red, or yellow."
|
||||
],
|
||||
"barrel": [
|
||||
"A barrel is a cylindrical container, meaning it has a circular cross section and a consistent diameter throughout its length.",
|
||||
|
||||
"Barrels are typically made of wood, although they can also be made of metal or plastic.",
|
||||
|
||||
" The wood staves of a barrel are bound together with metal hoops or bands that encircle the barrel.",
|
||||
|
||||
"The ends of a barrel are usually rounded and slightly convex, although some barrels have flat ends.",
|
||||
|
||||
"Barrels can come in a range of sizes, from small ones used for storing liquids like wine or whiskey, to large ones used for shipping goods like oil or grain."
|
||||
],
|
||||
"bass": [
|
||||
"Bass is a freshwater fish that belongs to the family of sunfish.",
|
||||
"They have an elongated and streamlined body shape.",
|
||||
"The color of the bass ranges from light green to dark green, with a white belly.",
|
||||
"The back of the bass is usually darker than the sides, and it has black stripes or blotches along the sides.",
|
||||
"The mouth of the bass is large, and it has a lower jaw that extends beyond the upper jaw."
|
||||
],
|
||||
"beaver": [
|
||||
"Beavers are large rodents that can grow up to 3-4 feet long.",
|
||||
"Beavers have a stocky and compact body with short legs.",
|
||||
"Beavers fur is dense, waterproof and varies in color from dark brown to reddish-brown.",
|
||||
"Beavers have a broad, flat tail covered in scales, which they use to swim, steer, and communicate with other beavers.",
|
||||
"Beavers have large, sharp front teeth that never stop growing, and they use them to cut down trees and build dams and lodges.",
|
||||
"Beavers eyes and ears are small and set back on their head to allow them to see and hear while swimming with most of their body submerged.",
|
||||
"Beavers have webbed hind feet that help them swim and dive underwater to forage for food or escape predators."
|
||||
],
|
||||
"binocular": [
|
||||
"Binocular is usually rectangular or oval-shaped, with a slightly curved surface to fit comfortably in the hands.",
|
||||
"The two lenses are set into the front of the device and are typically surrounded by a rubberized or plastic housing.",
|
||||
"There may be a small knob or lever in the center of the binocular that allows the user to adjust the distance between the two lenses, known as the interpupillary distance.",
|
||||
"On the top of binocular, there may be a small dial or knob that allows the user to focus each lens individually.",
|
||||
"The eyepieces are located on the back of the device and are typically covered with rubber or plastic cups that fit over the eyes.",
|
||||
"The device may also include additional features such as a neck strap, carrying case, or lens covers to protect the lenses when not in use."
|
||||
],
|
||||
"bonsai": [
|
||||
"A bonsai is a miniature tree that is grown and trained to have a specific shape and style.",
|
||||
"The tree is small in size, ranging from a few inches to a few feet tall.",
|
||||
"The trunk of the tree is often twisted or gnarled, giving it a unique and interesting appearance.",
|
||||
"The branches are carefully pruned and shaped to create a specific design or style, such as cascade, formal upright, or windswept.",
|
||||
"The leaves of the tree are also often smaller than those of a regular tree, and may be a different color or texture depending on the species.",
|
||||
"The bonsai is typically planted in a shallow pot or container that is designed to fit the small size of the tree."
|
||||
],
|
||||
"brain": [
|
||||
"The brain is a soft, spongy mass of tissue that is pinkish-gray in color.",
|
||||
"It is roughly the size and shape of a small cauliflower, with a wrinkled surface that is divided into two hemispheres.",
|
||||
"The hemispheres are connected by a thick bundle of nerve fibers called the corpus callosum.",
|
||||
"The brain is surrounded by three protective layers called the meninges, which help cushion it from injury.",
|
||||
"The brain is composed of billions of neurons, which are specialized cells that transmit signals throughout the body."
|
||||
],
|
||||
"brontosaurus": [
|
||||
"Brontosaurus was a massive dinosaur, measuring up to 75 feet in length and weighing around 30 tons.",
|
||||
"Brontosaurus had a long, slender neck and a bulky body with four thick legs.",
|
||||
"The head of a brontosaurus was small in proportion to its body and had a long snout with nostrils on the top.",
|
||||
"It had small, peg-like teeth that were suited for eating plants.",
|
||||
"The tail of a brontosaurus was long and whip-like, used for balance and communication.",
|
||||
"It is believed that the skin of a brontosaurus was covered in scales."
|
||||
],
|
||||
"buddha": [
|
||||
"A buddha has Serene and peaceful facial expression",
|
||||
"A buddha has Elongated earlobes, which symbolize the ability to hear the suffering of the world",
|
||||
"A buddha has A topknot or ushnisha on the head, which symbolizes wisdom and enlightenment",
|
||||
"A buddha has A third eye or urna on the forehead, which represents insight and intuition",
|
||||
"A buddha has A robe or simple clothing, symbolizing detachment and non-attachment to material things"
|
||||
],
|
||||
"butterfly": [
|
||||
"It has four wings, with intricate patterns and colors.",
|
||||
"The wings are thin and membranous, with veins running through them for support.",
|
||||
"The wings are covered in tiny scales that give them their vibrant colors.",
|
||||
"The body is slender and segmented, with three pairs of legs.",
|
||||
"The head has two large compound eyes and a long proboscis for feeding on nectar.",
|
||||
"The antennae are long and thin, with a bulbous end that helps the butterfly sense its surroundings.",
|
||||
"The size and shape of a butterfly can vary greatly depending on the species, but they typically range from 1-3 inches in wingspan."
|
||||
],
|
||||
"camera": [
|
||||
"A camera is typically rectangular in shape, with rounded corners.",
|
||||
"It has a lens, which is usually circular or oblong in shape and located on the front of the camera.",
|
||||
"The body of the camera is usually made of plastic, metal, or a combination of both.",
|
||||
"On the back of the camera, there is an LCD screen or viewfinder, which allows the user to see what they are photographing.",
|
||||
"A camera usually has buttons or dials on the top and back for adjusting settings such as shutter speed, aperture, and ISO.",
|
||||
"There is usually a flash located on the top of the camera, which can be manually or automatically activated.",
|
||||
"A camera may have a strap or grip on the side for easy carrying and handling."
|
||||
],
|
||||
"cannon": [
|
||||
"It is a large, heavy artillery piece made of metal.",
|
||||
"It has a long barrel that is often made of iron or steel.",
|
||||
"The barrel is mounted on a carriage or wheels for mobility.",
|
||||
"It has a breech loading mechanism that allows the gunpowder and projectile to be loaded from the rear of the barrel.",
|
||||
"The front end of the barrel has a muzzle or mouth where the projectile is fired.",
|
||||
"It may have a vent or touch-hole that is used to ignite the gunpowder.",
|
||||
"Cannons usually have a variety of features for aiming and firing, such as sights, elevation adjustments, and firing mechanisms.",
|
||||
"They may also have decorative features such as carvings or ornate designs."
|
||||
],
|
||||
"car side": [
|
||||
" A car side typically has four doors, two on each side, which are used to enter and exit the vehicle.",
|
||||
"The body of the car is usually made up of metal panels which are painted in a specific color.",
|
||||
"The car side may have windows or a sunroof, which allow passengers to see outside while driving.",
|
||||
"There may be side mirrors attached to the car doors, which provide a view of the area behind the car while driving.",
|
||||
"There may be handles or buttons on the car doors that allow passengers to open and close them easily.",
|
||||
"The car side may have wheels and tires, which are used to move the vehicle forward."
|
||||
],
|
||||
"ceiling fan": [
|
||||
"A circular or oval-shaped body housing the motor and fan blades.",
|
||||
"The fan blades, usually made of wood or plastic, attached to the motor housing.",
|
||||
"A mounting bracket that attaches the fan to the ceiling.",
|
||||
"A pull chain or switch to control the fan's speed and direction.",
|
||||
"Optional light fixture attached to the center of the fan."
|
||||
],
|
||||
"cellphone": [
|
||||
"Cellphones come in a variety of sizes, but most are around 5-6 inches in length and 2-3 inches in width.",
|
||||
|
||||
"The front of the cellphone is dominated by a large touchscreen display, which takes up most of the device's real estate.",
|
||||
|
||||
"While most functions on a cellphone are controlled through the touchscreen, there are usually a few physical buttons on the device as well. These may include a power button, volume rocker, and a home button.",
|
||||
|
||||
"Almost all cellphones have at least one camera, which is usually located on the back of the device."
|
||||
],
|
||||
"chair": [
|
||||
"A seat: This is the part of the chair that you sit on. It is usually flat and rectangular in shape.",
|
||||
|
||||
"A backrest: The backrest is the part of the chair that supports your back. It can be straight or curved, and it may be padded or not.",
|
||||
|
||||
"Legs: Most chairs have four legs, which provide stability and support. They can be made of wood, metal, or plastic.",
|
||||
|
||||
"Armrests: Some chairs have armrests, which provide additional support for your arms and shoulders.",
|
||||
|
||||
"Chairs can be made of a variety of materials, including wood, metal, plastic, or a combination of these materials."
|
||||
|
||||
],
|
||||
"chandelier": [
|
||||
"Chandelier typically has multiple arms or branches that radiate out from a central hub.",
|
||||
"Each arm may have a light bulb or candle holder at the end.",
|
||||
"The arms are often adorned with decorative elements such as crystals, beads, or glass shades.",
|
||||
"The central hub may also feature decorative elements, such as a large crystal or an ornate metal design.",
|
||||
"The chandelier may be round, oval, or have a more abstract shape."
|
||||
],
|
||||
"cougar body": [
|
||||
"They are approximately 4 to 6 feet long from nose to tail, and they can weigh between 90 and 200 pounds.",
|
||||
|
||||
"Cougars have a lean, muscular body that allows them to run fast and jump high.",
|
||||
|
||||
"Their fur is usually tan or brown, with black spots on their face and neck.",
|
||||
|
||||
"Their head is rounded, with a short snout, and they have large ears that are rounded at the tips.",
|
||||
|
||||
"Their tail is long and thick and can be up to one-third of their body length.",
|
||||
|
||||
"Their legs are powerful and muscular, with retractable claws that help them climb trees and catch prey.",
|
||||
|
||||
"They have big paws that help them run and jump, and they are also equipped with sharp claws that help them grip their prey."
|
||||
|
||||
],
|
||||
"cougar face": [
|
||||
"A large head with a rounded shape and prominent cheekbones.",
|
||||
"Short, rounded ears with white fur on the tips.",
|
||||
"A short, broad snout with a pinkish nose.",
|
||||
"Large, round eyes with vertical pupils that provide excellent vision in low light.",
|
||||
"Whiskers that are long, stiff, and black in color.",
|
||||
"The fur on the face is generally a light brown color."
|
||||
],
|
||||
"crab": [
|
||||
"Crabs have a hard, exoskeleton outer shell that protects their body.",
|
||||
"They have two large claws, called chelae, that they use for defense, feeding, and other tasks.",
|
||||
"Crabs have eight legs, which are attached to their body near the front.",
|
||||
"They have two stalked eyes that can move independently, which gives them a wide field of vision.",
|
||||
"Crabs come in a variety of colors and patterns, depending on the species. Some are brown, green, or red, while others have spots or stripes.",
|
||||
"They have a flattened body shape that allows them to scuttle along the ocean floor or crawl on land."
|
||||
],
|
||||
"crayfish": [
|
||||
"A crayfish is a small, freshwater crustacean that looks similar to a miniature lobster.",
|
||||
"They have a hard, shell-like exoskeleton that protects their body.",
|
||||
"Their body is segmented and divided into three parts: the head, thorax, and abdomen.",
|
||||
"The head has two pairs of antennae, one of which is longer than the other.",
|
||||
"Their eyes are located on stalks on the top of their head and can move independently of each other.",
|
||||
"They have eight legs, with the front two legs modified into claws or pincers.",
|
||||
"The color of their exoskeleton can vary depending on the species, but may be brown, green, blue, or red.",
|
||||
"They have gills located on the underside of their abdomen that help them breathe.",
|
||||
"Adult crayfish can range in size from 2 to 6 inches in length."
|
||||
],
|
||||
"crocodile": [
|
||||
"Crocodiles have a long and powerful body covered in tough, scaly skin.",
|
||||
"They have a large head with a pointed snout and sharp teeth.",
|
||||
"Their eyes and nostrils are positioned on the top of their head, allowing them to see and breathe while mostly submerged in water.",
|
||||
"Crocodiles have four short legs with webbed toes for swimming and walking on land.",
|
||||
"Their coloration varies from dark green to brown, with a lighter underbelly."
|
||||
],
|
||||
"crocodile head": [
|
||||
"Crocodile heads are typically triangular in shape.",
|
||||
"They have a long and pointed snout that is filled with sharp teeth.",
|
||||
"The upper jaw is wider than the lower jaw, and it has a distinctive V-shape.",
|
||||
"The eyes are located on top of the head, and they are positioned to allow the crocodile to see prey both above and below the water's surface.",
|
||||
"The nostrils are located on the top of the snout and they can be closed underwater to prevent water from entering the lungs.",
|
||||
"The skin on the head is rough and scaly, with a bumpy texture that is similar to the rest of the crocodile's body.",
|
||||
"The head is usually darker in color than the rest of the body, with shades of grey, black, or brown."
|
||||
],
|
||||
"cup": [
|
||||
"A cup is a cylindrical or conical shaped container used for drinking liquids.",
|
||||
"It is typically made of ceramic, glass, plastic, or metal.",
|
||||
"Cups range in size from small espresso cups to large mugs.",
|
||||
"The top of the cup is open and often has a lip or rim to make it easier to drink from.",
|
||||
"The cup has a handle on one side that is used to hold and lift the cup."
|
||||
],
|
||||
"dalmatian": [
|
||||
"A dalmatian is a medium to large-sized dog breed that is known for its distinctive black spots on a white coat.",
|
||||
|
||||
"Dalmatians have a muscular, athletic build with a deep chest and long legs.",
|
||||
"Their coat is short and smooth, and it has a white base color with black spots that can vary in size and shape.",
|
||||
"Some dalmatians may have liver-colored spots instead of black spots, but this is less common.",
|
||||
"They have a broad head with a long, tapering muzzle and dark eyes that are round and alert.",
|
||||
"Dalmatians have high-set, floppy ears that are triangular in shape and hang close to their head.",
|
||||
"Their tail is long, thin, and slightly curved upwards, and it is often spotted like the rest of their coat."
|
||||
],
|
||||
"dollar bill": [
|
||||
"A dollar bill is rectangular in shape and measures about 6.14 inches long and 2.61 inches wide.",
|
||||
"The front side of a dollar bill features the portrait of George Washington, the first president of the United States.",
|
||||
"Below the portrait is the denomination of the bill written as 'ONE DOLLAR' in green ink.",
|
||||
"The back side of the dollar bill features an image of the Great Seal of the United States, which includes an eagle with outstretched wings and a shield in front of it.",
|
||||
"The words THE UNITED STATES OF AMERICA appear on the top of the back side, while ONE DOLLAR is written in the center."
|
||||
],
|
||||
"dolphin": [
|
||||
"Dolphins are sleek and streamlined marine animals with a fusiform body shape, which means they have a tapered, torpedo-like body that helps them move quickly through the water.",
|
||||
"They have a curved dorsal fin on their back, which helps them maintain balance and stability while swimming.",
|
||||
"Dolphins have a long, pointed beak or rostrum that is used for catching fish and other prey.",
|
||||
"They have a pair of flippers or pectoral fins on either side of their body that are used for steering and maneuvering.",
|
||||
"Their tail or fluke is powerful and horizontally oriented, allowing them to swim at high speeds and jump out of the water.",
|
||||
"Dolphins have a smooth, rubbery skin that is usually gray or blue-gray in color, with a lighter underside."
|
||||
],
|
||||
"dragonfly": [
|
||||
"A dragonfly has Long, slender body with two pairs of wings",
|
||||
"A dragonfly has Large compound eyes that cover most of its head",
|
||||
"A dragonfly has Thin, elongated abdomen with several segments",
|
||||
"A dragonfly has Six legs that are used for perching and catching prey",
|
||||
"A dragonfly has Brightly colored body with metallic or iridescent hues",
|
||||
"A dragonfly has Wings that are transparent and have intricate patterns",
|
||||
"A dragonfly has Two pairs of wings that are capable of independent movement",
|
||||
"A dragonfly has Long, slender wings that are held perpendicular to the body when at rest"
|
||||
],
|
||||
"electric guitar": [
|
||||
"A electric guitar has A solid or semi-hollow body made of wood or other materials",
|
||||
"A electric guitar has A long, thin neck made of wood with metal frets",
|
||||
"A electric guitar has Six metal strings, usually made of steel or nickel, which run from the bridge of the guitar to the headstock",
|
||||
"A electric guitar has One or more pickups, which are magnetic devices that capture the sound of the strings and send it to an amplifier",
|
||||
"A electric guitar has Volume and tone controls, usually located on the body of the guitar, which allow the player to adjust the sound of the guitar",
|
||||
"A electric guitar has A whammy bar or tremolo arm, which allows the player to change the pitch of the strings",
|
||||
"A electric guitar has Tuning pegs, usually located on the headstock, which allow the player to adjust the tension of the strings and tune the guitar to different pitches"
|
||||
],
|
||||
"elephant": [
|
||||
"An elephant is a large mammal that typically stands between 8 and 13 feet tall and can weigh anywhere from 2.5 to 7 tons.",
|
||||
|
||||
"They have a distinctive trunk, which is a fusion of their upper lip and nose, that can be used for a variety of tasks including grasping objects, breathing, and making sounds.",
|
||||
"Their ears are large and fan-shaped, and they use them to cool off their bodies by flapping them back and forth.",
|
||||
"Elephants have thick gray skin that is wrinkled and tough, providing protection from predators and the sun.",
|
||||
"Their tusks are long, curved teeth that protrude from their upper jaw and are used for defense, digging, and manipulating objects.",
|
||||
"Elephants have four pillar-like legs that are strong and sturdy, allowing them to support their massive size."
|
||||
],
|
||||
"emu": [
|
||||
"An emu is a large, flightless bird native to Australia.",
|
||||
"It can grow up to 6.2 feet (1.9 meters) tall and weigh up to 121 pounds (55 kilograms).",
|
||||
"Emus have long, slender necks and small, rounded heads with a beak at the end.",
|
||||
"Their feathers are brownish-gray and shaggy, providing insulation from both heat and cold.",
|
||||
"Emus have powerful legs with three-toed feet. Their toes are equipped with sharp claws for defense and foraging.",
|
||||
"They are known for their ability to run at high speeds of up to 30 miles (48 kilometers) per hour.",
|
||||
"Male emus have a distinctive blue patch of skin on their necks that turns purple during breeding season."
|
||||
],
|
||||
"euphonium": [
|
||||
"The Euphonium is a brass instrument that is similar to a small tuba.",
|
||||
|
||||
"It has a conical bore and a large bell that flares out at the end.",
|
||||
|
||||
"The instrument is typically made of brass and has a shiny, gold or silver plated finish.",
|
||||
|
||||
"It has three or four valves that are played with the fingers of the right hand.",
|
||||
|
||||
"The euphonium has a curved shape and is held in front of the player, with the bell facing upwards."
|
||||
|
||||
],
|
||||
"ewer": [
|
||||
"An ewer is a type of pitcher or jug that is typically used for pouring liquids.",
|
||||
|
||||
"Ewers are typically made of ceramic, glass, metal, or other similar materials.",
|
||||
"They have a narrow spout at the top that is used for pouring liquids.",
|
||||
"The body of an ewer is often curved or rounded, with a wider base that tapers up towards the top.",
|
||||
"Many ewers have a handle on one side, which makes it easier to hold and pour."
|
||||
],
|
||||
"ferry": [
|
||||
"A ferry is a type of boat that is designed to transport people, vehicles, and cargo across a body of water.",
|
||||
|
||||
"Size: Ferries can vary in size, but they are typically larger than most boats. They can range from small passenger ferries that carry only a few people to large car ferries that can transport hundreds of vehicles and passengers.",
|
||||
|
||||
"Shape: Ferries usually have a flat bottom and a wide beam in order to provide stability and accommodate large vehicles. The bow and stern are often squared off to allow for easy loading and unloading.",
|
||||
|
||||
"Decking: Ferries have multiple levels or decks for passengers and vehicles. The lower decks are used for cars and trucks, while the upper decks are for passengers.",
|
||||
|
||||
"Wheelhouse: The bridge or wheelhouse is usually located on the upper deck and is where the captain and crew operate the ferry."
|
||||
],
|
||||
"flamingo": [
|
||||
"Flamingos are tall birds, reaching up to 4-5 feet (1.2-1.5 meters) in height.",
|
||||
"They have long, thin legs that are usually pink in color.",
|
||||
"Their bodies are relatively small and slender, with a curved neck and a small, pointed beak.",
|
||||
"The feathers on their bodies are mostly pink, with darker pink or red coloring on the wings and tail.",
|
||||
"Their eyes are small and black, and they have a distinctive black and white stripe that runs across their face and down their neck."
|
||||
],
|
||||
"flamingo head": [
|
||||
"Flamingos have a long, thin beak that is typically black or dark gray in color.",
|
||||
"The upper part of the beak is slightly curved, while the lower part is straight.",
|
||||
"Above the beak, flamingos have two small, black eyes that are set deep into their skull.",
|
||||
"The skin around a flamingo's eyes is usually pale pink or white.",
|
||||
"Flamingos have a distinctive featherless area on their face called the lore. This patch of skin is usually a brighter pink or red color than the rest of the bird's body."
|
||||
],
|
||||
"garfield": [
|
||||
"Garfield is a cartoon character, created by Jim Davis in 1978.",
|
||||
"He is an orange tabby cat with black stripes and a round body.",
|
||||
"Garfield has a large head with big, expressive eyes and a small nose.",
|
||||
"He has short, stubby legs with four toes on each paw.",
|
||||
"Garfield is often depicted wearing a collar with a bell, and sometimes a red bowtie."
|
||||
],
|
||||
"gerenuk": [
|
||||
"A gerenuk is a type of antelope that is native to East Africa.",
|
||||
"They are relatively small, standing at around 3-4 feet tall at the shoulder.",
|
||||
"Their most distinctive feature is their long, slender necks, which they use to reach up and eat leaves from tall trees.",
|
||||
"Gerenuks have reddish-brown fur on their backs and white fur on their bellies, with a darker stripe running down their sides.",
|
||||
"Both males and females have curved horns, which can grow up to around 10 inches long."
|
||||
],
|
||||
"gramophone": [
|
||||
"A gramophone, also known as a phonograph, is a device used for playing recorded sounds, especially music.",
|
||||
"It has a turntable or rotating platform made of metal or plastic where the vinyl record sits.",
|
||||
"The turntable is connected to a motor that spins it at a constant speed.",
|
||||
"The tonearm is a long, thin arm that swings over the record and holds the stylus or needle.",
|
||||
"The stylus or needle is a small, pointed piece of metal that rests on the grooves of the record and vibrates as it passes over them."
|
||||
|
||||
],
|
||||
"grand piano": [
|
||||
"A grand piano is a large musical instrument that is typically found in concert halls, recording studios, and grand homes.",
|
||||
"Size: A grand piano is a large instrument that typically ranges in size from 4 feet 6 inches to 9 feet long.",
|
||||
|
||||
"Shape: The shape of a grand piano is elongated and rectangular, with a curved tail that extends outward from the main body.",
|
||||
|
||||
"Lid: A grand piano has a hinged lid that can be propped open to expose the strings and soundboard.",
|
||||
|
||||
"Keyboard: The keyboard of a grand piano is composed of 88 keys, which are arranged in a series of white and black keys."
|
||||
],
|
||||
"hawksbill": [
|
||||
"A hawksbill is a medium-sized sea turtle that has a distinctive appearance.",
|
||||
|
||||
"The hawksbill has a flattened body and a tapered head that comes to a sharp point.",
|
||||
"Its shell, or carapace, is hard and bony with a distinctive pattern of overlapping scales, or scutes.",
|
||||
"The scutes on the carapace are raised and have a coloration that varies from brown to black with streaks of gold, orange, or red.",
|
||||
"The hawksbill has two pairs of prefrontal scales on the top of its head, which is a unique characteristic among sea turtles."
|
||||
],
|
||||
"headphone": [
|
||||
"A headphone is a pair of audio devices designed to cover the ears and deliver sound directly to the listener.",
|
||||
"It typically has two ear cups connected by a headband that rests on top of the head.",
|
||||
"The ear cups are made of plastic or metal and are padded with foam or leather cushions to provide comfort and prevent sound leakage.",
|
||||
"The ear cups are usually adjustable and can be rotated or pivoted to fit the shape of the listener's head.",
|
||||
"The headband is also adjustable and can be loosened or tightened to fit different head sizes."
|
||||
],
|
||||
"hedgehog": [
|
||||
"Size: It is typically around 5-12 inches (13-30 cm) in length.",
|
||||
"Body Shape: It has a spiny coat of sharp spines or quills that cover its back and sides. The quills are typically brown or black in color and can be up to 1.5 inches (4 cm) long.",
|
||||
"Facial Features: It has a pointed snout and small eyes and ears.",
|
||||
"Limbs: It has four short legs with claws that are used for digging and climbing.",
|
||||
"Color: Its underbelly is usually lighter in color than its back and sides, ranging from white to beige."
|
||||
],
|
||||
"helicopter": [
|
||||
"A helicopter typically has a long, slender body with a pointed nose and a rounded tail.",
|
||||
"It has a main rotor on top, which is a large horizontal blade that spins around and provides lift.",
|
||||
"There is often a smaller rotor at the tail, which is used for stability and steering.",
|
||||
"The cockpit is located near the front of the helicopter and usually has a large windshield for visibility.",
|
||||
"The body of the helicopter may be painted in different colors or patterns depending on its purpose or the company that owns it."
|
||||
],
|
||||
"ibis": [
|
||||
"An ibis is a medium to large-sized bird with a long, curved bill that is typically down-curved.",
|
||||
"They have a slender, streamlined shape with long legs and necks.",
|
||||
"The feathers on their body are predominantly white, with some species having black or dark feathers on their wings or tails.",
|
||||
"Some species of ibis have distinctive bare skin patches around their face and throat that can be brightly colored, such as red, blue, or green.",
|
||||
"Their wingspan can range from 50-60 inches, depending on the species."
|
||||
],
|
||||
"inline skate": [
|
||||
"An inline skate consists of a boot that fits around the foot and ankle.",
|
||||
"Attached to the bottom of the boot are three or four wheels that are arranged in a straight line.",
|
||||
"The wheels are made of hard plastic and are designed to roll smoothly over a flat surface.",
|
||||
"Inline skates also have a frame that connects the wheels and provides support for the boot. The frame is usually made of aluminum or other lightweight metals.",
|
||||
"There is a brake on the back of one of the skates, which allows the skater to slow down or stop their forward motion."
|
||||
],
|
||||
"joshua tree": [
|
||||
"A Joshua tree is a type of tree that belongs to the Yucca genus and is native to the southwestern United States, particularly the Mojave Desert.",
|
||||
"The tree can grow up to 40 feet tall, but often averages around 15-20 feet in height.",
|
||||
"The trunk of a Joshua tree is typically thick and gnarled, with a rough, scaly texture.",
|
||||
"The branches of the tree are also thick and twisting, and often have numerous smaller branches and twigs growing off of them.",
|
||||
"The leaves of a Joshua tree are long and narrow, with sharp points at the end, and grow in clusters at the end of the branches."
|
||||
],
|
||||
"kangaroo": [
|
||||
"Kangaroos are marsupials, which means they carry their young in a pouch on their belly.",
|
||||
"They have large, powerful hind legs that are built for hopping and jumping. In fact, kangaroos are the only large animals that use hopping as their primary means of locomotion.",
|
||||
"Kangaroos are covered in fur that can range in color from gray, brown, and red to black or white.",
|
||||
"They have a long, muscular tail that helps them balance when hopping and jumping, and can also be used as a powerful weapon if threatened.",
|
||||
"Kangaroos have a distinctive, elongated snout with a small mouth and large ears. Their ears are especially important for detecting predators and other potential threats."
|
||||
],
|
||||
"ketch": [
|
||||
"A ketch is a type of sailing vessel that is characterized by two masts, with the main mast being taller than the mizzen mast.",
|
||||
"A ketch typically has a long, narrow hull with a pointed bow and stern.",
|
||||
"The main mast is located towards the front of the vessel, while the mizzen mast is towards the back.",
|
||||
"The main mast is taller than the mizzen mast, and both masts are usually wooden.",
|
||||
"The sails on a ketch are typically triangular in shape, with the mainsail being larger than the mizzen sail.",
|
||||
"A ketch usually has a cockpit area towards the back of the vessel, where the helmsman can steer the boat."
|
||||
],
|
||||
"lamp": [
|
||||
"It has a base that sits on a surface, such as a table or desk.",
|
||||
"A stem or post rises from the base, which can be straight or curved.",
|
||||
"At the top of the stem, there is a socket that holds the light bulb.",
|
||||
"The bulb is covered by a lampshade, which can come in various shapes and materials.",
|
||||
"The lampshade can be attached to the socket or to the stem itself."
|
||||
],
|
||||
"laptop": [
|
||||
"A laptop is a portable computer that typically has a clamshell design.",
|
||||
"It has a screen that is attached to a keyboard base.",
|
||||
"The screen can range in size from 11 inches to 17 inches, depending on the model.",
|
||||
"The keyboard is similar in layout to a desktop computer keyboard, but may be smaller to fit within the laptop's compact design.",
|
||||
"Laptops often have a touchpad or trackpad located below the keyboard for cursor control."
|
||||
],
|
||||
"llama": [
|
||||
"Llamas are domesticated animals that belong to the camel family.",
|
||||
"They are about 5.5 to 6 feet tall at the shoulder and weigh between 250 to 400 pounds.",
|
||||
"Llamas have a long neck and relatively small head with large eyes and pointed ears.",
|
||||
"Their coat is thick and fluffy, which can be various shades of brown, white, black, or grey.",
|
||||
" Llamas have a long tail that is covered with fur, which can be braided or left free."
|
||||
],
|
||||
"lobster": [
|
||||
"A lobster is a marine crustacean that has the following characteristics:",
|
||||
|
||||
"A hard exoskeleton that protects its body.",
|
||||
"A long, segmented body with a distinct head and tail.",
|
||||
"Two large, pincer-like claws that are used for defense and catching prey.",
|
||||
"Eight smaller legs that are used for walking and swimming."
|
||||
],
|
||||
"lotus": [
|
||||
"A lotus is a beautiful aquatic plant that is native to Asia, Australia, and North America. Here are some points to describe what a lotus looks like:",
|
||||
|
||||
"The lotus plant has large, circular leaves that float on the surface of the water.",
|
||||
"The flowers of the lotus are large and showy, with a distinct shape that is often compared to a water lily.",
|
||||
"The petals of the lotus flower are typically pink or white, although other colors such as yellow and red can also occur.",
|
||||
"One of the most distinctive features of the lotus flower is its seed pod, which is shaped like a cone and has many small holes."
|
||||
],
|
||||
"mandolin": [
|
||||
"A mandolin is a stringed instrument that typically has eight strings, divided into four pairs.",
|
||||
"The body of a mandolin is usually shaped like a teardrop or an elongated oval, with a rounded back and a flat or slightly curved top.",
|
||||
"The top of the mandolin is often made of spruce or other types of wood, while the back and sides may be made of maple or other hardwoods.",
|
||||
"The neck of the mandolin is slender and may be made of maple or other woods, with frets inserted into the fingerboard to help the player find the correct notes.",
|
||||
"The strings of a mandolin are often tuned in pairs, with the lower pair tuned to the same notes as a violin's G string, the middle pair tuned to the same notes as a violin's D string, and the upper pair tuned to the same notes as a violin's A string."
|
||||
],
|
||||
"mayfly": [
|
||||
"- A mayfly is a small insect, typically measuring around 1-2 centimeters in length.",
|
||||
"- It has a slender, elongated body with two pairs of delicate, transparent wings that are held upright when at rest.",
|
||||
"- The body is usually brown, gray or green in color, and is divided into three distinct segments: the head, thorax, and abdomen.",
|
||||
"- The head has two large, compound eyes, two short antennae, and a pair of mouthparts for feeding on plant matter and algae.",
|
||||
"- The thorax is where the wings and six jointed legs are attached. The legs are used for walking and clinging to surfaces, while the wings are used for flight."
|
||||
],
|
||||
"menorah": [
|
||||
" A menorah is a traditional Jewish candelabrum that is primarily used during the Hanukkah celebration.",
|
||||
|
||||
"- A menorah typically has eight branches or arms, plus one additional center branch or arm.",
|
||||
"- The branches are evenly spaced and extend outward from a central stem or base.",
|
||||
"- Each branch or arm holds a candle or lamp, for a total of nine lights.",
|
||||
"- The center branch, known as the shamash, is usually taller or positioned higher than the other branches and is used to light the other candles."
|
||||
],
|
||||
"metronome": [
|
||||
"A metronome is a device that helps musicians keep a steady tempo while playing music.",
|
||||
"A typical metronome is a small, box-shaped device that sits on a flat surface.",
|
||||
"It usually stands about 4-5 inches tall and is roughly 2 inches wide and deep.",
|
||||
" The metronome has a pendulum arm that swings back and forth at a set tempo.",
|
||||
"The arm is attached to a weight that can be moved up or down the arm to adjust the tempo."
|
||||
],
|
||||
"minaret": [
|
||||
" A minaret is a tall, slender tower that is typically part of a mosque.",
|
||||
"It is usually built of brick or stone and can be square, rectangular, or cylindrical in shape.",
|
||||
"The tower can range in height from just a few meters to over 60 meters tall.",
|
||||
" At the top of the minaret, there is often a balcony or platform that is surrounded by a railing or balustrade.",
|
||||
" Many minarets are decorated with intricate designs, such as geometric patterns or calligraphy, that are carved into the stone or brickwork."
|
||||
],
|
||||
"nautilus": [
|
||||
"A nautilus is a marine animal that lives in the deep sea.",
|
||||
|
||||
"It has a spiral-shaped shell that is divided into chambers.",
|
||||
"The shell is usually white or brown with distinctive ridges and grooves.",
|
||||
"The nautilus has a soft body that is hidden inside its shell.",
|
||||
"It has multiple tentacles with a total of about 90-100 tentacles."
|
||||
],
|
||||
"octopus": [
|
||||
"Octopuses typically have a rounded, bulbous head with eight long tentacles that radiate outwards from the base of the head.",
|
||||
"The tentacles are usually lined with suction cups or suckers that help the octopus grip onto surfaces or prey.",
|
||||
"Octopuses have a soft, flexible body that can change shape and texture to blend in with their surroundings. They may also change color to camouflage themselves or communicate with other octopuses.",
|
||||
"Some species of octopus have distinct markings, patterns or textures on their skin. For example, the mimic octopus can mimic the appearance and movement of other sea creatures to avoid predators.",
|
||||
"Octopuses have a beak-like mouth in the center of their lower body that they use to crush and eat their prey. They have no bones, so they can squeeze through very small spaces."
|
||||
],
|
||||
"okapi": [
|
||||
"An okapi is an unusual mammal that looks like a combination of a giraffe, a zebra, and a horse.",
|
||||
"An okapi has a reddish-brown coat with white stripes on its legs and hindquarters, similar to a zebra.",
|
||||
"Its neck is long like a giraffe, and it has a small head with large, round ears.",
|
||||
"Okapis have a distinctive black and white pattern on their face, similar to that of a raccoon.",
|
||||
"They have a long, black tongue that they use to reach leaves and buds on trees."
|
||||
],
|
||||
"pagoda": [
|
||||
"A pagoda is a type of tower-like structure that is commonly found in Asia.",
|
||||
|
||||
"Pagodas are typically tall and slender structures.",
|
||||
|
||||
"They are often made of wood, stone, brick, or a combination of these materials.",
|
||||
|
||||
"Pagodas have multiple tiers or levels, with each level getting smaller as it goes up.",
|
||||
"The roofs of pagodas are usually curved or sloped, and they often feature elaborate decorations, such as dragons or other mythical creatures."
|
||||
],
|
||||
"panda": [
|
||||
"Pandas are black and white bears with a round body shape and short legs.",
|
||||
"Their fur is mostly white with black patches around their eyes, ears, shoulders, legs, and feet.",
|
||||
"They have black fur around their eyes, which makes them look like they are wearing eye masks.",
|
||||
"Pandas have large, round heads with flat faces and black noses.",
|
||||
"Their ears are black and rounded, and they have a very good sense of hearing."
|
||||
],
|
||||
"pigeon": [
|
||||
"Pigeons are typically gray or brown in color, with varying shades and patterns. Some may have iridescent feathers on their necks and wings.",
|
||||
"They have a plump, round body shape and a small head.",
|
||||
"Pigeons have a short, stout beak that is slightly curved downwards.",
|
||||
"Their eyes are round and black, with a thin white ring around the pupil.",
|
||||
"Pigeons have relatively short legs, and their feet have three toes pointing forward and one pointing backwards."
|
||||
],
|
||||
"pizza": [
|
||||
"A pizza is usually round in shape, but it can also come in square or rectangular shapes.",
|
||||
"It is made up of a crust, toppings, and sauce.",
|
||||
"The crust is typically a thin layer of dough, but it can also be thick and fluffy or stuffed with cheese.",
|
||||
"Toppings can include cheese, meats (such as pepperoni or sausage), vegetables (like tomatoes or onions), and sometimes even fruit or seafood.",
|
||||
"The sauce is usually tomato-based but can also be made with other ingredients like pesto or barbecue sauce."
|
||||
],
|
||||
"platypus": [
|
||||
"The platypus is a unique-looking animal with a mix of features from different animal groups.",
|
||||
"It has a broad, flat tail similar to a beaver's, which helps it swim.",
|
||||
"Its body is covered in thick, waterproof fur that ranges from dark brown to gray in color.",
|
||||
"The platypus has webbed feet with sharp claws that it uses to dig burrows in riverbanks.",
|
||||
"Its most distinctive feature is its bill, which is flat and wide like a duck's bill, but with a sensitive, rubbery snout that helps it detect prey underwater."
|
||||
],
|
||||
"pyramid": [
|
||||
"A pyramid is a three-dimensional geometric shape that has a polygonal base and triangular faces that meet at a single point, called the apex.",
|
||||
|
||||
"Pyramids have a square, rectangular, or triangular base.",
|
||||
"The base of a pyramid is connected to triangular faces that slope upward towards a point.",
|
||||
"The point where all the triangular faces meet is called the apex.",
|
||||
"The height of a pyramid is the distance from the base to the apex"
|
||||
],
|
||||
"revolver": [
|
||||
"A revolver is a type of firearm that typically has the following characteristics:",
|
||||
|
||||
"Barrel: Revolvers usually have a long metal tube, called the barrel, that extends out from the front of the firearm.",
|
||||
|
||||
"Cylinder: The cylinder is a round component that holds the ammunition. It rotates to allow each chamber to line up with the barrel for firing.",
|
||||
|
||||
"Trigger: The trigger is the mechanism that activates the firing pin, which in turn ignites the primer in the ammunition.",
|
||||
|
||||
"Grip: The grip is the handle of the revolver that the shooter holds onto. It is usually made of wood or plastic and is designed to fit comfortably in the hand."
|
||||
],
|
||||
"rhino": [
|
||||
"Rhinos are large, heavy animals that typically weigh around 1,000 to 2,000 pounds.",
|
||||
"They have short, stocky legs that are designed to support their weight and help them move quickly.",
|
||||
"Their skin is thick and gray, with a rough, textured appearance that is covered in folds and wrinkles.",
|
||||
"Some species of rhino have a large, distinctive horn on their nose, while others have two smaller horns.",
|
||||
"Their heads are large and blocky, with a blunt snout and small, beady eyes."
|
||||
],
|
||||
"rooster": [
|
||||
"A rooster is a male chicken and typically has the following physical features:",
|
||||
|
||||
"The head is adorned with a red comb and wattles (fleshy protuberances) that hang down from the chin.",
|
||||
"It has a curved, pointed beak that is used for pecking and eating.",
|
||||
"The eyes are large and dark, with a sharp, intense gaze.",
|
||||
"The neck is long and slender, with a ruff of feathers around the base."
|
||||
],
|
||||
"saxophone": [
|
||||
"A saxophone is a musical instrument that belongs to the woodwind family. It is made of brass and has a distinctive shape.",
|
||||
|
||||
"The saxophone has a long, curved body with a bell-shaped end.",
|
||||
"It has a mouthpiece that is attached to a neck, which is then connected to the body of the instrument.",
|
||||
"The body of the saxophone has keys and buttons that the player can press to change the pitch and produce different notes.",
|
||||
"The saxophone also has a thin metal reed, which is attached to the mouthpiece."
|
||||
],
|
||||
"schooner": [
|
||||
"It has two or more masts, with the forward mast being shorter than the aft mast.",
|
||||
"The sails are usually fore-and-aft rigged, meaning they run parallel to the length of the ship.",
|
||||
"It has a fairly narrow hull with a sharp bow and a flat or slightly rounded bottom.",
|
||||
"The deck is typically low and sleek, with a raised platform at the stern for the helmsman.",
|
||||
"It often has a bowsprit, a spar that extends from the bow and supports the jib sails"
|
||||
],
|
||||
"scissors": [
|
||||
"A scissors is a tool used for cutting and has the following features:",
|
||||
|
||||
"Two sharp blades",
|
||||
"Two finger holes for gripping",
|
||||
"A pivot point that allows the blades to open and close",
|
||||
"A handle for comfort and control"
|
||||
],
|
||||
"scorpion": [
|
||||
"Scorpions have a segmented body with eight legs and a pair of large pincers called pedipalps.",
|
||||
|
||||
"They have a curved tail that usually ends in a stinger.",
|
||||
|
||||
"Scorpions have a tough exoskeleton that varies in color from yellowish-brown to black.",
|
||||
|
||||
"They range in size from 1 inch to 8 inches long, depending on the species.",
|
||||
|
||||
"Scorpions have two small eyes on the top of their head, but they rely on their sense of touch and vibrations to detect prey and predators."
|
||||
],
|
||||
"sea horse": [
|
||||
"A seahorse is a small marine fish with a distinctive appearance.",
|
||||
|
||||
"A seahorse has a long, narrow body that is covered in bony plates instead of scales.",
|
||||
"Its head is shaped like a horse's head, with a long snout and a rounded forehead.",
|
||||
"Seahorses have two small, beady eyes set on either side of their head.",
|
||||
"They have a small, vertical mouth that is surrounded by a ring of tentacles that they use to catch their prey."
|
||||
],
|
||||
"snoopy": [
|
||||
"A small, white, and furry dog with long droopy ears and a black nose.",
|
||||
"It has black oval-shaped eyes with a black outline and thick black eyebrows.",
|
||||
"It has a small round tail that curves upward.",
|
||||
"It usually wears a red collar with a dog tag that has its name on it.",
|
||||
"It is often depicted wearing a red doghouse with a white roof." ],
|
||||
"soccer ball": [
|
||||
"A soccer ball is round in shape.",
|
||||
"It is typically made of synthetic leather or rubber.",
|
||||
"The ball is usually black and white in color, featuring pentagonal and hexagonal shapes.",
|
||||
"The pentagons and hexagons on the ball are arranged in a specific pattern, often referred to as a truncated icosahedron.",
|
||||
"The ball has a circumference of about 28 inches and a weight of about 14-16 ounces."
|
||||
],
|
||||
"stapler": [
|
||||
"A stapler is a common office accessory that is used to bind sheets of paper together.",
|
||||
|
||||
"It is made of plastic or metal.",
|
||||
"It has a rectangular or cylindrical shape.",
|
||||
"It has a base that serves as a platform for placing the paper to be stapled.",
|
||||
"It has a hinge mechanism that allows the top part to be lifted up to insert staples."
|
||||
],
|
||||
"starfish": [
|
||||
"A starfish has a distinct shape that resembles a star or a pentagon.",
|
||||
"It has five arms (although some species can have more) that radiate out from a central disk.",
|
||||
"The arms are generally long and thin, tapering towards the tip.",
|
||||
"The skin of a starfish is rough and bumpy, often covered in small spines or bumps.",
|
||||
"Starfish come in a variety of colors, including red, orange, yellow, blue, and green."
|
||||
],
|
||||
"stegosaurus": [
|
||||
"A stegosaurus is a large, herbivorous dinosaur that lived during the late Jurassic period.",
|
||||
|
||||
"The stegosaurus had a distinctive appearance with a long, narrow head, short neck, and a large, round body.",
|
||||
"It had four short legs, each with three toes that ended in hoof-like claws.",
|
||||
"The back of the stegosaurus was covered in a series of large, bony plates that extended down the length of its spine.",
|
||||
"These plates were arranged in pairs and alternated in size, with the larger ones located toward the center of the back and the smaller ones toward the tail."
|
||||
],
|
||||
"stop sign": [
|
||||
"A stop sign is a red, octagonal-shaped sign that is used to regulate traffic.",
|
||||
|
||||
"Shape: The stop sign is octagonal in shape, which means it has eight sides.",
|
||||
"Color: The sign is predominantly red, with white lettering on it.",
|
||||
"Lettering: The word STOP is written in all capital letters in white color in the center of the sign.",
|
||||
"Border: The word STOP is surrounded by a white border to make it more visible."
|
||||
],
|
||||
"strawberry": [
|
||||
"A strawberry is a small, red fruit with a green stem and leaves on top.",
|
||||
"It has a round or slightly pointed shape, with a slightly flattened bottom.",
|
||||
"The surface of the strawberry is covered in small, yellowish seeds that are embedded in the flesh.",
|
||||
"The flesh of the strawberry is juicy and translucent, and has a slightly grainy texture due to the seeds.",
|
||||
"The skin of the strawberry is usually shiny and smooth, with a slightly waxy feel."
|
||||
],
|
||||
"sunflower": [
|
||||
"Sunflowers are tall plants that can grow up to 10 feet (3 meters) in height.",
|
||||
"The stem of a sunflower is thick and sturdy, and covered in small hairs.",
|
||||
"The leaves of a sunflower are large and green, and often have a rough texture.",
|
||||
"The flower of a sunflower is large and round, with a diameter of up to 12 inches (30 centimeters).",
|
||||
"Sunflowers have a distinctive yellow color, with petals that radiate outwards from a dark center."
|
||||
],
|
||||
"tick": [
|
||||
"Ticks are small, arachnid-like creatures that range in size from a grain of sand to the size of a small grape.",
|
||||
"They have a round or oval-shaped body that is flattened and becomes engorged as they feed on blood.",
|
||||
"Their body is often brown, black, or reddish-brown in color and has a tough, leathery texture.",
|
||||
"Ticks have eight legs that are positioned close to their body, making them difficult to remove once they have attached themselves to a host.",
|
||||
"Their mouthparts are designed to pierce the skin of their host and suck blood, which can cause irritation, itching, and the transmission of diseases."
|
||||
],
|
||||
"trilobite": [
|
||||
"A trilobite is an extinct marine arthropod that lived from the Cambrian period to the Permian period.",
|
||||
"It has a distinctive three-lobed body shape, with a head, thorax, and pygidium (tail).",
|
||||
"The body is covered in a hard, calcified exoskeleton that is divided into segments, which allowed for flexibility and movement.",
|
||||
"The head has two large, compound eyes that are thought to have been some of the first sophisticated eyes in the animal kingdom.",
|
||||
"The head also has antennae and mouthparts for feeding." ],
|
||||
"umbrella": [
|
||||
"An umbrella is a common tool used to protect people from rain or sunlight.",
|
||||
"It consists of a long, slender central shaft or pole, made of metal or plastic.",
|
||||
"Attached to the top of the shaft is a series of thin, flexible metal ribs or spokes, which form the structure of the umbrella.",
|
||||
"These ribs are covered by a canopy made of waterproof fabric, such as nylon or polyester, which is stretched over them.",
|
||||
"The canopy is usually circular or hexagonal in shape and can vary in size from small to large, depending on the type of umbrella."
|
||||
],
|
||||
"watch": [
|
||||
"Round or square face: The face of the watch is usually round or square and contains the dial and hands.",
|
||||
|
||||
"Dial: The dial displays the time and may include markings for minutes, hours, and seconds.",
|
||||
|
||||
"Hands: The hands on the watch move around the dial to indicate the time.",
|
||||
|
||||
"Numerals or markers: The numerals or markers around the watch face indicate the hours or minutes.",
|
||||
|
||||
"Crown: The crown is used to set the time and date on the watch."
|
||||
],
|
||||
"water lilly": [
|
||||
"Water lilies are aquatic plants that float on the surface of still or slow-moving bodies of water, such as ponds or lakes.",
|
||||
"They have large, round leaves that can grow up to 30 cm (12 in) in diameter. The leaves are usually green, but can also be purple or reddish in color.",
|
||||
"Water lily flowers are large and showy, with many petals arranged in a circular pattern. The petals are usually white or pink, but can also be yellow or orange.",
|
||||
"The flowers are supported by long, slender stalks that rise above the water's surface. The stalks can be up to 1 meter (3 ft) tall.",
|
||||
"Water lilies have long, thick roots that anchor them in the mud or sediment at the bottom of the water. The roots can be several meters long and are often covered in fine, hair-like structures that help to absorb nutrients from the water."
|
||||
],
|
||||
"wheelchair": [
|
||||
"A wheelchair is a mobility device used by people who have difficulty walking or cannot walk at all.",
|
||||
"It consists of a seat, backrest, footrests, and two large wheels at the back and two smaller wheels at the front.",
|
||||
"The seat and backrest are usually made of padded materials for comfort.",
|
||||
"The footrests are adjustable and swing away for easy transfer in and out of the chair.",
|
||||
"The wheels are usually made of rubber and have push rims for the user to propel themselves."
|
||||
],
|
||||
"wild cat": [
|
||||
"Wild cats are typically medium to large-sized felines, with an average weight of around 20-40 pounds (9-18 kg).",
|
||||
"They have muscular bodies, with short, dense fur that can come in a variety of colors and patterns, depending on the species. For example, a leopard has a distinctive pattern of black rosettes on a golden-orange background, while a tiger has vertical black stripes on a reddish-orange coat.",
|
||||
"Wild cats have sharp, retractable claws that they use for hunting and climbing.",
|
||||
"Their heads are usually round or oval-shaped, with short, rounded ears, and large, expressive eyes that range in color from yellow to green to blue.",
|
||||
"Some species of wild cats, like lions and tigers, have distinctive manes or tufts of hair on their ears, while others, like cheetahs and leopards, have more streamlined features."
|
||||
],
|
||||
"windsor chair": [
|
||||
"It has a solid wooden seat that is usually saddle-shaped.",
|
||||
"The backrest is composed of several thin vertical spindles or rods.",
|
||||
"The legs are turned or tapered and are joined to the seat with mortise and tenon joints.",
|
||||
"The arms, if present, are usually curved and supported by additional spindles.",
|
||||
"The chair may have a decorative crest rail at the top of the backrest."
|
||||
],
|
||||
"wrench": [
|
||||
"A wrench is a tool used for tightening or loosening bolts, nuts, and other fasteners.",
|
||||
|
||||
"A wrench typically has a long and slender body with a curved or angled shape.",
|
||||
"At one end of the body, there is a fixed or adjustable jaw that can grip the fastener.",
|
||||
"The jaw is usually flat and smooth to prevent damage to the fastener.",
|
||||
"At the other end of the body, there is a handle that provides leverage for turning the wrench."
|
||||
],
|
||||
"yin yang": [
|
||||
"A circular symbol with two halves of equal size.",
|
||||
"One half of the symbol is black and the other half is white.",
|
||||
"There is a small circle of the opposite color within each half.",
|
||||
"The black half of the symbol has a white dot in the center, while the white half has a black dot in the center.",
|
||||
"The two halves of the symbol are connected by a curved line that separates them."
|
||||
]
|
||||
}
|
||||
2446
gpt_file/dtd_prompt.json
Normal file
122
gpt_file/eurosat_prompt.json
Normal file
@@ -0,0 +1,122 @@
|
||||
{
|
||||
"Annual Crop Land": [
|
||||
"A centered satellite photo of Annual Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Annual Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Annual Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Annual Crop Land would also include any buildings or roads that are near the field.",
|
||||
"A centered satellite photo of Annual Crop Land would also show any roads or paths that lead to the crop land.",
|
||||
"A centered satellite photo of Annual Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Annual Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Annual Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Annual Crop Land would look like one large, continuous field of green.",
|
||||
"A centered satellite photo of Annual Crop Land may also show irrigation systems or other farming infrastructure."
|
||||
],
|
||||
"Forest": [
|
||||
"A centered satellite photo of Forest Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Forest Land would look like a large green area with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Forest Land would look like a dense, green area with few or no bare patches of earth.",
|
||||
"A centered satellite photo of Forest Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Forest Land would look like a large green field with small patches of brown or bare earth in between. A centered satellite photo of Grassland would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Forest would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Forest Land would look like a large playing field with lots of trees.",
|
||||
"A centered satellite photo of Forest Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Forest would look like a green or dark green field with patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Forest Land would look like a large green area with small patches of brown or bare earth in between."
|
||||
],
|
||||
"Herbaceous Vegetation Land": [
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a large green or brown field with small patches of green or brown in between.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a green field with small patches of brown of bare earth in between. A centered satellite photo of Tree Cover would look like a green field with small patches of brown or bare earth in between, and a few trees scattered throughout.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a field of green with a few brown spots in between.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a green field with a few trees or bushes mixed in.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a green field with very small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a large green field with small patches of brown or bare earth in between. A centered satellite photo of Perennial Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Herbaceous Vegetation Land would look like a large, green field with small patches of brown or bare earth in between."
|
||||
],
|
||||
"Highway or Road": [
|
||||
"A centered satellite photo of Highway or Road Land would look like a long, thin, dark strip with small patches of green or brown on either side.",
|
||||
"A centered satellite photo of Highway or Road Land would look like a large paved road with small patches of green or brown on either side.",
|
||||
"A centered satellite photo of Highway or Road would look like a thin, dark line winding through a lighter-colored background.",
|
||||
"A centered satellite photo of Highway or Road Infrastructure would look like a large number of dark lines running across the landscape.",
|
||||
"A centered satellite photo of Highway or Road Infrastructure would look like a thin line of asphalt with a small patch of gravel or dirt on each side.",
|
||||
"A centered satellite photo of Highway or Road Land would look like a long, straight, grey line with small patches of green or brown on either side.",
|
||||
"A centered satellite photo of Highway or Road Infrastructure would look like a spider web of grey or white lines with small patches of green or brown in between.",
|
||||
"A centered satellite photo of Highway or Road Land would look like a large number of thin, dark lines criss-crossing each other.",
|
||||
"A centered satellite photo of Highway or Road Land would look like a large brown or gray road with green fields on either side.",
|
||||
"A centered satellite photo of Highway or Road Land would look like a spider web of thin, black lines."
|
||||
],
|
||||
"Industrial Buildings": [
|
||||
"A centered satellite photo of Industrial Buildings would look like a cluster of buildings, usually gray or white, surrounded by a parking lot.",
|
||||
"A centered satellite photo of Industrial Buildings would look like a group of large structures with small parking lots around them.",
|
||||
"A centered satellite photo of Industrial Buildings would look like a series of low, rectangular buildings with roofs of different colors.",
|
||||
"A centered satellite photo of Industrial Buildings would look like large, dark buildings amid a matrix of smaller, lighter buildings.",
|
||||
"A centered satellite photo of Industrial Buildings would look like a city with large buildings and smokestacks.",
|
||||
"A centered satellite photo of Industrial Buildings would look like a city with a few buildings that are taller than the others.",
|
||||
"A centered satellite photo of Industrial Buildings would look like a densely populated area with many buildings and roads.",
|
||||
"A centered satellite photo of Industrial Buildings would look like large connected buildings surrounded by asphalt parking lots.",
|
||||
"A centered satellite photo of Industrial Buildings would look like a bunch of large angular buildings with small streets in between them.",
|
||||
"A centered satellite photo of Industrial Buildings would look like a series of large Modern highrises in an urban area."
|
||||
],
|
||||
"Pasture Land": [
|
||||
"A centered satellite photo of Pasture Land would look like large green fields with animals grazing on them.",
|
||||
"A centered satellite photo of Pasture Land would look like a large green field with some areas of brown or bare earth in between.",
|
||||
"A centered satellite photo of Pasture Land would look like a large green field broken up by areas of trees, bushes, or other foliage.",
|
||||
"A centered satellite photo of Pasture Land would look like large green fields with small areas of brown or bare earth in between.",
|
||||
"A centered satellite photo of Pasture Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Pasture Land would look like a large green or tan field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Pasture Land would look like a large green or brown field with small patches of different colors in between.",
|
||||
"A centered satellite photo of Pasture Land would look like a large field of green with small brown or black spots (cows).",
|
||||
"A centered satellite photo of Pasture Land would look like large green fields with some areas of brown or bare earth in between.",
|
||||
"A centered satellite photo of Pasture Land would look like large green fields with small patches of brown or bare earth in between."
|
||||
],
|
||||
"Permanent Crop Land": [
|
||||
"A centered satellite photo of Permanent Crop Land would look like a large field with different colors depending on what crop is being grown.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a large green field with smaller, more uniform green patches in between.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a green field with small patches of brown earth or water in between.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a large green field with a few smaller green or brown fields in between.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a large green field with small patches of brown or bare earth in between, and there would also be small patches of different colors representing different types of permanent crops.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a large green field with small patches of brown or bare earth in between.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a mosaic of different colors, depending on the type of crop being grown.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a similar green field, however the patches of brown or bare earth would be much smaller, as there is less open land in between crops.",
|
||||
"A centered satellite photo of Permanent Crop Land would look like a large green or brown field with small patches of bare earth in between."
|
||||
],
|
||||
"Residential Buildings": [
|
||||
"A centered satellite photo of Residential Buildings would look like a city with tall buildings in the center and smaller buildings on the outskirts.",
|
||||
"A centered satellite photo of Residential Buildings would look like a city with large buildings and concrete roads. A centered satellite photo of a Commercial Harbor would look like a harbor with many boats and a few warehouses.",
|
||||
"A centered satellite photo of Residential Buildings would look like many small rectangular buildings that are close together with some green space in between them.",
|
||||
"A centered satellite photo of Residential Buildings would look like a lot of small buildings close together with some green space in between them.",
|
||||
"A centered satellite photo of Residential Buildings would look like a city with areas of green trees and parks throughout.",
|
||||
"A centered satellite photo of Residential Buildings would look like a city with tall buildings in the center and lower buildings or houses on the outskirts.",
|
||||
"A centered satellite photo of Residential Buildings would look like a bunch of small squares with a variety of colors.",
|
||||
"A centered satellite photo of Residential Buildings would look like a large number of small, square or rectangular shaped buildings with large open spaces in between.",
|
||||
"A centered satellite photo of Residential Buildings would look like a large number of small, square or rectangular buildings with small patches of green or bare earth in between.",
|
||||
"A centered satellite photo of Residential Buildings would look like a small city with many houses and buildings."
|
||||
],
|
||||
"River": [
|
||||
"A centered satellite photo of River Delta would look like a large mass of water with small islands or patches of land in between.",
|
||||
"A centered satellite photo of River would look like many small streams or rivers flowing through a larger body of water.",
|
||||
"A centered satellite photo of River would look like a long, thin blue line with small tributaries branching off of it.",
|
||||
"A centered satellite photo of River would look like a thin blue line winding through a larger green area.",
|
||||
"A centered satellite photo of River would look like a long, thin blue or green line winding its way through a landscape.",
|
||||
"A centered satellite photo of River would look like a large blue or green body of water with smaller tributaries feeding into it.",
|
||||
"A centered satellite photo of River would look like a large blue body of water with small patches of green or brown land on either side.",
|
||||
"A centered satellite photo of River Delta would look like a series of branching streams or rivers flowing into a larger body of water.",
|
||||
"A centered satellite photo of River would look like a long, thin body of water with trees or other landforms surrounding it.",
|
||||
"A centered satellite photo of River Delta would look like a large body of water with many small waterways flowing into it."
|
||||
],
|
||||
"Sea or Lake": [
|
||||
"A centered satellite photo of Sea or Lake would look like a large blue circle with small patches of green, white, or brown around the edge.",
|
||||
"A centered satellite photo of Sea or Lake Ice would look like a large white or blue field with small patches of ocean water in between.",
|
||||
"A centered satellite photo of Sea or Lake would look like a large dark blue body of water with small white or light-colored areas around the edge.",
|
||||
"A centered satellite photo of Sea or Lake Ice would look like a large body of white with small patches of blue in between.",
|
||||
"A centered satellite photo of Sea or Lake ice would look like a large white or light blue field with small patches of dark blue or black in between.",
|
||||
"A centered satellite photo of Sea or Lake would look like a large blue or green body of water with small islands in it.",
|
||||
"A centered satellite photo of Sea or Lake would look like a large dark blue body with small areas of whitecaps where the waves are crashing.",
|
||||
"A centered satellite photo of Sea or Lake ice would look like large white fields with small patches of dark water in between.",
|
||||
"A centered satellite photo of Sea or Lake ice would look like large white areas with smaller areas of dark water in between.",
|
||||
"A centered satellite photo of Sea or Lake Ice would look like a large white or light blue area with bits of dark blue in the middle."
|
||||
]
|
||||
}
|
||||
5202
gpt_file/fgvc_prompt.json
Normal file
5254
gpt_file/food101_prompt.json
Normal file
51898
gpt_file/imagenet_prompt.json
Normal file
1226
gpt_file/oxford_flowers_prompt.json
Normal file
446
gpt_file/oxford_pets_prompt.json
Normal file
@@ -0,0 +1,446 @@
|
||||
{
|
||||
"abyssinian": [
|
||||
"A photo of a pet abyssinian. it has a lean body, long neck, wedge-shaped head. Its coat is short, coarse, and in ruddy color.",
|
||||
"A photo of a pet abyssinian. it has a long neck, long face, pointy ears. It's coat is short and in silver color.",
|
||||
"A photo of a pet abyssinian. it has a short coat that is ticked with various colors. It is a very active and playful cat.",
|
||||
"A photo of a pet abyssinian. it has a arched back, long face, big ears. It's coat is soft, dense, and in ruddy color.",
|
||||
"A photo of a pet abyssinian. it has long neck, short face, erect ears. It's coat is medium length, thick, and in ruddy color.",
|
||||
"A photo of a pet abyssinian. it has long neck, thin face, big ears. Its coat is long, silky, and in black color.",
|
||||
"A photo of a pet abyssinian. it has a medium-length coat that is variegated with different colors. It has long, elegant ears, and a slim build.",
|
||||
"A photo of a pet abyssinian. it is a medium sized cat with a short coat that is reddish brown with darker brown spots.",
|
||||
"A photo of a pet abyssinian. it has a long body and short legs, its coat is short and in ruddy color.",
|
||||
"A photo of a pet abyssinian. it has long, elegant legs, and a coat that is soft, fine, and in ruddy color."
|
||||
],
|
||||
"american bulldog": [
|
||||
"A photo of a pet american bulldog. it has a thick neck, short face, floppy ears. It's coat is short and in brindle color.",
|
||||
"A photo of a pet american bulldog. it has wide nostrils, thick limbs, and a short coat.",
|
||||
"A photo of a pet american bulldog. it looks like a boxer.",
|
||||
"A photo of a pet american bulldog. it is a mix between an English Bulldog and a Pit Bull.",
|
||||
"A photo of a pet american bulldog. it has a short head with a flat forehead and a short face. The coat is short and in brindle colors.",
|
||||
"A photo of a pet american bulldog. it has a thick neck, wide head, and pointy ears. It's coat is short and straight, and in white color.",
|
||||
"A photo of a pet american bulldog. it may be used as a working dog, but is typically a family pet.",
|
||||
"A photo of a pet american bulldog. it is a mix of several different types of bulldogs.",
|
||||
"A photo of a pet american bulldog. it has a lot of energy and loves to play.",
|
||||
"A photo of a pet american bulldog. which is a type of bulldog that was developed in the United States."
|
||||
],
|
||||
"american pit bull terrier": [
|
||||
"A photo of a pet american pit bull terrier. it has muscular body, short coat, and it is often used in dog fighting.",
|
||||
"A photo of a pet american pit bull terrier. it has short, stiff fur, and a large head. The coat is usually white with patches of black or brown.",
|
||||
"A photo of a pet american pit bull terrier. it has short coat, straight, and in brindle color.",
|
||||
"A photo of a pet american pit bull terrier. it has thick neck, short face, cropped ears. It's coat is short, straight, and in fawn color.",
|
||||
"A photo of a pet american pit bull terrier. it has a large head, a short coat that is mostly white with some brown patches, and its ears are floppy.",
|
||||
"A photo of a pet american pit bull terrier. a type of bulldog.",
|
||||
"A photo of a pet american pit bull terrier. it has a thick neck, short face, and cropped ears. It's coat is short, stiff, and in fawn color.",
|
||||
"A photo of a pet american pit bull terrier. which has a similar appearance, but with a longer snout and ears that stand up.",
|
||||
"A photo of a pet american pit bull terrier. it has thick neck, short face, upright ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet american pit bull terrier. it has short coat, sturdy build, and a broad head. It is also in brindle color."
|
||||
],
|
||||
"basset hound": [
|
||||
"A photo of a pet basset hound. it has long droopy ears, its coat is short, dense, and its color is black and tan.",
|
||||
"A photo of a pet basset hound. it has a long body, short legs, big ears. It's coat is long, dense, and in black & tan color.",
|
||||
"A photo of a pet basset hound. it has droopy ears, long body, and its coat is long, straight, and in tri-color.",
|
||||
"A photo of a pet basset hound. it has long body, short legs, big ears. It's coat is long, straight, and in brindle color.",
|
||||
"A photo of a pet basset hound. it has long ears, a long body, and a short coat. The coat is usually tri-colored, with black, brown, and white.",
|
||||
"A photo of a pet basset hound. it has long ears and a long body. Its coat is short and in a tri-color. This is a pet beagle, it has long ears and a short coat. The coat is usually black, white, and brown.",
|
||||
"A photo of a pet basset hound. it has short legs and a long body. It's coat is short, dense, and in tricolor.",
|
||||
"A photo of a pet basset hound. it has short legs, long body, and floppy ears. It's coat is short and in tri-color (black, brown, and white).",
|
||||
"A photo of a pet basset hound. it has long droopy ears, a long face, and a short coat. The coat is soft and in tri-color.",
|
||||
"A photo of a pet basset hound. it has long body, short legs, floppy ears. It's coat is long, smooth, and in tri-color. This is a pet golden retriever, it has thick neck, long face, long ears. It's coat is thick,"
|
||||
],
|
||||
"beagle": [
|
||||
"A photo of a pet beagle. it has long ears and legs, and a smooth coat that is tri-color.",
|
||||
"A photo of a pet beagle. it has long ears, long snout, and is tri-colored.",
|
||||
"A photo of a pet beagle. it has thin neck, short face, floppy ears. Its coat is short and tri-colored.",
|
||||
"A photo of a pet beagle. it has a medium length neck, long ears, medium face. It's coat is medium, in black and tan color.",
|
||||
"A photo of a pet beagle. it has thin neck, short face, floppy ears. It's coat is short, straight, and in black color.",
|
||||
"A photo of a pet beagle. it has a long neck, long face, floppy ears. It's coat is long, straight, and in brown and white colors.",
|
||||
"A photo of a pet beagle. it has a long, narrow head, long ears, and a sleek coat. The coat is usually tricolored-- brown, black, and white.",
|
||||
"A photo of a pet beagle. it has thin neck, short face, floppy ears. Its coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet beagle. it has a short back, floppy ears, and big dark eyes. Its coat is short and in a tri-color pattern.",
|
||||
"A photo of a pet beagle. it has thin neck, short face, floppy ears. It's coat is short, straight, and in brindle color."
|
||||
],
|
||||
"bengal": [
|
||||
"A photo of a pet bengal. it has long body, large spots, and long tail.",
|
||||
"A photo of a pet bengal. it has short fur, spots, and a long tail.",
|
||||
"A photo of a pet bengal. it has a long neck, short face, pointy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet bengal. it has short fur, big spots, and a long tail.",
|
||||
"A photo of a pet bengal. it has long neck, short face, big floppy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet bengal. it has a thick coat, short face, and erect ears. The coat is usually one solid color, with spots.",
|
||||
"A photo of a pet bengal. it has a big neck, short face, floppy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet bengal. it has a thick neck, broad face, and small ears. It's coat is black, orange, and in spots.",
|
||||
"A photo of a pet bengal. it has a thick neck, short face, and large ears. It's coat is short, soft, and in a light brown color with black spots.",
|
||||
"A photo of a pet bengal. it has spots, is medium sized, and its coat is short and dense."
|
||||
],
|
||||
"birman": [
|
||||
"A photo of a pet birman. it has a thick neck, long face, pointy ears. It's coat is long, fluffy, and in seal mitted color.",
|
||||
"A photo of a pet birman. it has a fluffy coat, pointed ears, and blue eyes.",
|
||||
"A photo of a pet birman. it has long fur, pointed ears, and blue eyes. It's coat is in seal point color.",
|
||||
"A photo of a pet birman. it has a long coat, pointed ears, and its coat is in seal, chocolate, blue, lilac, or red point colors.",
|
||||
"A photo of a pet birman. it has long fur, pointed ears, and is in cream color.",
|
||||
"A photo of a pet birman. it has long hair, pointed ears, and is seal point color.",
|
||||
"A photo of a pet birman. it has long neck, flat face, pointy ears. It's coat is long, fluffy, and in pointed color.",
|
||||
"A photo of a pet birman. it is a domestic cat with a coat that has a dark brown color around its body and bright white paws. It has a long face and ears.",
|
||||
"A photo of a pet birman. it has long fur, pointed ears, and blue eyes.",
|
||||
"A photo of a pet birman. it has a long neck, long face, and pointy ears. It's coat is long, fluffy, and in seal color."
|
||||
],
|
||||
"bombay": [
|
||||
"A photo of a pet bombay. it has thin neck, short face, floppy ears. Its coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet bombay. it has a broad head, a blunt muzzle, and a round body. Its coat is black and shiny.",
|
||||
"A photo of a pet bombay. it is a shorthair, and it is black.",
|
||||
"A photo of a pet bombay. it is a domesticated house cat. It has a slender body, black fur, and copper eyes.",
|
||||
"A photo of a pet bombay. it is a medium sized cat with a short coat that is black with silver spots. It has green eyes and a short tail.",
|
||||
"A photo of a pet bombay. it has short, thick fur, and it is black.",
|
||||
"A photo of a pet bombay. it has long neck, flat face, and small ears. It's coat is black, and in Bombay pattern.",
|
||||
"A photo of a pet bombay. it has black fur, and green eyes.",
|
||||
"A photo of a pet bombay. which is a type of Siamese cat. It has a short face, long body, and pointed ears. Its coat is sleek, short, and seal point colored.",
|
||||
"A photo of a pet bombay. it has a broad neck, short face, and large ears. It's coat is short, straight, and in brindle color."
|
||||
],
|
||||
"boxer": [
|
||||
"A photo of a pet boxer. it has short neck, short face, and floppy ears. Its coat is short, straight, and fawn in color.",
|
||||
"A photo of a pet boxer. it has short, square head, short muzzle, and black coat.",
|
||||
"A photo of a pet boxer. it has a short coat, muscular body, and a square shaped head. The coat is usually fawn or brindle.",
|
||||
"A photo of a pet boxer. it has thin neck, short face, floppy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet boxer. it has a long neck, short face, and floppy ears. Its coat is short and in brindle color.",
|
||||
"A photo of a pet boxer. it has short coat, pointed ears, and is in fawn color.",
|
||||
"A photo of a pet boxer. it has a short muzzle, square jaw, and cropped ears. It's coat is short and glossy, and in fawn color.",
|
||||
"A photo of a pet boxer. it has a short neck, short face, and square-shaped head. It's coat is short and in brindle color.",
|
||||
"A photo of a pet boxer. it has short coat, brindle color, and a square head.",
|
||||
"A photo of a pet boxer. it has a muscular body, broad chest, and a short tail. Its coat is short, smooth, and in brindle color."
|
||||
],
|
||||
"british shorthair": [
|
||||
"A photo of a pet british shorthair. it has a broad face, short nose, big eyes, and a short coat. The coat is blue in color.",
|
||||
"A photo of a pet british shorthair. it has a broad chest, short legs, and a round head. Its coat is dense, short, and in blue color.",
|
||||
"A photo of a pet british shorthair. it has a broad chest, short legs, and a round head. It's coat is short, dense, and in blue color.",
|
||||
"A photo of a pet british shorthair. it has short legs, round head, short nose and ears. The coat is short and dense, in blue color.",
|
||||
"A photo of a pet british shorthair. it has a broad face, round eyes, and a short coat that is blue in color.",
|
||||
"A photo of a pet british shorthair. it has broad shoulders, short face, round eyes. It's coat is short and dense, in blue color.",
|
||||
"A photo of a pet british shorthair. it has a stocky body, short legs, and a short round face. It's coat is dense, thick, and in blue color.",
|
||||
"A photo of a pet british shorthair. it has thick fur, round face, and big eyes. Its coat is in blue color.",
|
||||
"A photo of a pet british shorthair. it has round head, short face, and huge eyes. It's coat is short, dense, and in blue color.",
|
||||
"A photo of a pet british shorthair. it has a chubby face, short ears, and a round body. It's coat is short and dense, and in blue color."
|
||||
],
|
||||
"chihuahua": [
|
||||
"A photo of a pet chihuahua. it has big ears, short legs, and a long body. It's coat is short and in brown color.",
|
||||
"A photo of a pet chihuahua. it has a big head, short legs, and a long body. It's coat is short, straight, and in fawn color.",
|
||||
"A photo of a pet chihuahua. it has large ears, long coat, and it is in black and tan color.",
|
||||
"A photo of a pet chihuahua. it has a large head, upright ears, and a long tail. It's coat is short, and in brown and white colors.",
|
||||
"A photo of a pet chihuahua. it has a long neck, short face, and pointy ears. It's coat is long, straight, and in black color.",
|
||||
"A photo of a pet chihuahua. it has slim body, long snout, and pointy ears. Its coat is long and in tan color.",
|
||||
"A photo of a pet chihuahua. it has a small body, round head, big eyes. It's coat is smooth and in brown color.",
|
||||
"A photo of a pet chihuahua. it has short legs, long body, pointy ears. It's coat is long, silky, and in cream/white color.",
|
||||
"A photo of a pet chihuahua. it has small ears, large eyes, and a short snout. The chihuahua's coat is short, smooth, and can be any color.",
|
||||
"A photo of a pet chihuahua. it has thin neck, short face, long ears. It's coat is short, straight, and in beige color."
|
||||
],
|
||||
"egyptian mau": [
|
||||
"A photo of a pet egyptian mau. it has short fur, and is in silver color.",
|
||||
"A photo of a pet egyptian mau. it has a slender body, long neck, short face, and short ears. It's coat is short, fine, and in silver color.",
|
||||
"A photo of a pet egyptian mau. it has a thin neck, short face, large ears. It's coat is short and in silver color.",
|
||||
"A photo of a pet egyptian mau. it has short fur, long body, and a face that looks like a lion.",
|
||||
"A photo of a pet egyptian mau. it has short fur, long snout, and round eyes. Mau's come in a range of colors, including blue, bronze, smoke, and silver.",
|
||||
"A photo of a pet egyptian mau. it is a domestic cat which is characterized by slender body, long legs, and long neck. It is a shorthair cat with silver-ticked tabby coat and green eyes.",
|
||||
"A photo of a pet egyptian mau. it has a long slender body, long neck, and long legs. The coat is silky, short, and in black and silver spotted color.",
|
||||
"A photo of a pet egyptian mau. it has a slender body, long neck, wedge-shaped head, and large ears. The coat is short and in silver-blue color.",
|
||||
"A photo of a pet egyptian mau. it is a domestic cat that has a short coat that is silver and black in color, with spots and stripes.",
|
||||
"A photo of a pet egyptian mau. it is a domestic cat that comes in a variety of colors. It has a short coat and is relatively small."
|
||||
],
|
||||
"english cocker spaniel": [
|
||||
"A photo of a pet english cocker spaniel. it has long ears, a long nose, and a silky coat. It is in a black and white color.",
|
||||
"A photo of a pet english cocker spaniel. it has long, silky fur that is usually in black and brown colors. This is a pet golden retriever, it has a thick, water-resistant coat that is in gold, cream, or black color.",
|
||||
"A photo of a pet english cocker spaniel. it has rounded head, long ears, and a coat that is either straight or wavy. Its coat is in liver and white color.",
|
||||
"A photo of a pet english cocker spaniel. it has long, feathered ears, long face, and a silky, wavy coat. It is black and white in color.",
|
||||
"A photo of a pet english cocker spaniel. it has long, floppy ears, a long nose, and a silky coat. It is usually black or brown in color.",
|
||||
"A photo of a pet english cocker spaniel. it has floppy ears and a long face. Its coat is medium length and in brown and white color.",
|
||||
"A photo of a pet english cocker spaniel. it has longer face and ears. The coat is medium in length, and can be either straight or wavy. It is also in brindle color.",
|
||||
"A photo of a pet english cocker spaniel. it has long ears, a long nose, and a thick coat. It is also in a brindle color.",
|
||||
"A photo of a pet english cocker spaniel. it has long floppy ears, a long nose, and a coat that is long, silky, and in chestnut color.",
|
||||
"A photo of a pet english cocker spaniel. it has long neck, long face, floppy ears. It's coat is medium length, thick, in black & brown color."
|
||||
],
|
||||
"english setter": [
|
||||
"A photo of a pet english setter. it has long legs, long nose, and it's coat is in a ticking pattern.",
|
||||
"A photo of a pet english setter. it has a long neck, short face, long ears. It's coat is long, wavy, and in red and white color.",
|
||||
"A photo of a pet english setter. it has medium-length ears, long face, and long neck. Its coat is silky, wavy, and in a black and white color.",
|
||||
"A photo of a pet english setter. it has long neck, long face, erect ears. It's coat is long, dense, and in a liver color.",
|
||||
"A photo of a pet english setter. it has long neck, thin face, long ears. It's coat is wavy, straight, and in brown color.",
|
||||
"A photo of a pet english setter. it has long neck, short face, erect ears. It's coat is medium length, straight, and in silvery-white color.",
|
||||
"A photo of a pet english setter. it has long neck, long face, pointy ears. It's coat is medium length, wavy, and in chestnut color.",
|
||||
"A photo of a pet english setter. it has a long face, long ears, and a long coat. It is a hunting dog.",
|
||||
"A photo of a pet english setter. it has a long body, long face, and long ears. It's coat is silky, wavy, and in golden color.",
|
||||
"A photo of a pet english setter. it has a long neck, pointed nose, and long ears. It's coat is medium length, straight, and in black and white color."
|
||||
],
|
||||
"german shorthaired": [
|
||||
"A photo of a pet german shorthaired. it has a sleek coat, muscular body, and pointed ears.",
|
||||
"A photo of a pet german shorthaired. it has a square head, pointed ears, and a docked tail. Its coat is short and dense, in liver and white color.",
|
||||
"A photo of a pet german shorthaired. it has long body, pointy ears, and docked tail. The coat is dense, short, and in liver color.",
|
||||
"A photo of a pet german shorthaired. it's a hunting dog. German shorthaired have medium to dense coat that is straight or wavy, and can be either smooth or wirehaired. They have strong, muscular body and they are very active. This is a pet beagle, it",
|
||||
"A photo of a pet german shorthaired. it is a hunting and versatile breed.",
|
||||
"A photo of a pet german shorthaired. it has a broad back, pointed ears. Its coat is white with brown spots.",
|
||||
"A photo of a pet german shorthaired. it has a short coat, it is black and white in color. It has a long nose and floppy ears.",
|
||||
"A photo of a pet german shorthaired. it has short coat, floppy ears, and it is tricolor.",
|
||||
"A photo of a pet german shorthaired. it has a medium sized head, floppy ears, and a coat that is short, straight, and brown.",
|
||||
"A photo of a pet german shorthaired. it is a silent dog."
|
||||
],
|
||||
"great pyrenees": [
|
||||
"A photo of a pet great pyrenees. it has thick fur, long face, triangular ears. It's coat is in cream color.",
|
||||
"A photo of a pet great pyrenees. it has thick neck, long face, small ears. It's coat is long and in pure white color.",
|
||||
"A photo of a pet great pyrenees. it has thick neck, short face, floppy ears. It's coat is thick, straight, and in brindle color.",
|
||||
"A photo of a pet great pyrenees. it has thick neck, short face, floppy ears. It's coat is short, straight, and in white color.",
|
||||
"A photo of a pet great pyrenees. it has a thick coat that is white in color. It has a large head, and its ears are triangular in shape.",
|
||||
"A photo of a pet great pyrenees. it has a thick, wooly coat that is white with some brown patches. It has a large head, big eyes, and a large, fluffy tail.",
|
||||
"A photo of a pet great pyrenees. it has a thick coat, long body, and large head. It is often used as a guard dog.",
|
||||
"A photo of a pet great pyrenees. it has thick neck, long face, pointed ears. It's coat is long, thick, and in white color.",
|
||||
"A photo of a pet great pyrenees. it has thick cream colored coat, big head, and big body. It is a very friendly dog, and is great with children.",
|
||||
"A photo of a pet great pyrenees. it has thick neck, long face, erect ears. It's coat is thick, long, and in white color."
|
||||
],
|
||||
"havanese": [
|
||||
"A photo of a pet havanese. it has a thick, double coat that is either straight or slightly curly. The coat can be any color, but is most commonly seen in white, black, or a mix of both.",
|
||||
"A photo of a pet havanese. it has long silky coat, in different colors like black, white, gold, or a mix. It has a teddy bear like face, and its ears are long and floppy.",
|
||||
"A photo of a pet havanese. it has long ears, a long face, and a thick coat. The coat is white with black spots.",
|
||||
"A photo of a pet havanese. it has silky, long hair. It is a small breed of dog. It has a short snout and big, dark eyes.",
|
||||
"A photo of a pet havanese. it has a long, curved face, and long, floppy ears. It's coat is long and curly, and in white color.",
|
||||
"A photo of a pet havanese. it has long neck, long face, pointy ears. It's coat is fluffy, curly, and in black color.",
|
||||
"A photo of a pet havanese. it has a long body, short face, and longer coat. It is a small dog.",
|
||||
"A photo of a pet havanese. it has long neck, long face, perky ears. It's coat is long and in white color.",
|
||||
"A photo of a pet havanese. it has thin neck, short face, floppy ears. It's coat is long, silky, and in cream color.",
|
||||
"A photo of a pet havanese. it has a long and silky coat, it is white with black spots. It has floppy ears and a black nose."
|
||||
],
|
||||
"japanese chin": [
|
||||
"A photo of a pet japanese chin. it has a thin neck and short face with a pointed chin. Its coat is long and silky and in black and white color.",
|
||||
"A photo of a pet japanese chin. it has a thin body, short face, and large eyes. It's coat is in black and white color.",
|
||||
"A photo of a pet japanese chin. which has a long coat that is either red or black and white. It has a flat face and large, erect ears.",
|
||||
"A photo of a pet japanese chin. it has a thick round body, short legs, a flat face, and large eyes. It's coat is long and silky, and in a black and white color.",
|
||||
"A photo of a pet japanese chin. it has long, fur, floppy ears, and round eyes.",
|
||||
"A photo of a pet japanese chin. it has a thick coat, small face, and its ears fold over. It is also in brindle color.",
|
||||
"A photo of a pet japanese chin. it has a long face, pointed ears, and its coat is in black and white color.",
|
||||
"A photo of a pet japanese chin. it has a square-shaped head, small, black eyes, and a black nose. The coat is long, silky, and in black and white color.",
|
||||
"A photo of a pet japanese chin. it has a puffy face, small eyes, and a long coat that is either straight or wavy. It can be black and white, red and white, or tricolored.",
|
||||
"A photo of a pet japanese chin. it has long thick coat and a very small face."
|
||||
],
|
||||
"keeshond": [
|
||||
"A photo of a pet keeshond. it has thick neck, long face, erect ears. It's coat is thick, dense, and in black and gray color.",
|
||||
"A photo of a pet keeshond. it has a thick coat that is gray and black in color and a thick ruff around its neck. It has erect ears and a wedge shaped head.",
|
||||
"A photo of a pet keeshond. it has a thick neck, short face, and floppy ears. Its coat is thick, wavy, and in black and silver color.",
|
||||
"A photo of a pet keeshond. a spitz-type dog. It has a thick, double coat that is usually silver and black in color. It has a pointed muzzle, and its ears stand erect.",
|
||||
"A photo of a pet keeshond. it has thick neck, short face, and erect ears. Its coat is long and in various shades of gray.",
|
||||
"A photo of a pet keeshond. it has a thick neck, wedge-shaped head, and pointed ears. It's coat is thick, long, and in silver-grey and black.",
|
||||
"A photo of a pet keeshond. it has thin neck, short face, floppy ears. It's coat is longer, and in black and silver color.",
|
||||
"A photo of a pet keeshond. it has a thick neck and coat, it is also in brindle color.",
|
||||
"A photo of a pet keeshond. it has a thick coat that is usually silver-grey and black in color. It has a bushy tail that it often curls over its back.",
|
||||
"A photo of a pet keeshond. pelted coat, erect ears, and a pointed muzzle."
|
||||
],
|
||||
"leonberger": [
|
||||
"A photo of a pet leonberger. it has thick fur around its neck, a short nose, and large, drooping ears. The coat is in a light brown color with black markings.",
|
||||
"A photo of a pet leonberger. it has a thick neck, short face, dark eyes. Its coat is thick, straight, and in lion color.",
|
||||
"A photo of a pet leonberger. it has a thick neck, long face, and erect ears. Its coat is long, wavy, and in black and tan color.",
|
||||
"A photo of a pet leonberger. it has thick neck, long face, and erect ears. It's coat is long and in yellow-brown color.",
|
||||
"A photo of a pet leonberger. it has a thick neck and a lion-like mane. It's coat is long and wavy, and in a golden color.",
|
||||
"A photo of a pet leonberger. it has a long neck, long face, and erect ears. Its coat is thick, and in shiny black color.",
|
||||
"A photo of a pet leonberger. it has a thick neck, long face, and small ears. Its coat is thick, fluffy, and in lion coloration.",
|
||||
"A photo of a pet leonberger. it has a thick neck, short face, floppy ears. It's coat is thick, straight, and in brindle color.",
|
||||
"A photo of a pet leonberger. it is a giant breed of dog. It has a thick coat that is heavy and long, and in black, red, or yellow color.",
|
||||
"A photo of a pet leonberger. it has thick neck, long face, and erect ears. It's coat is thick, wavy, and in brown and black color."
|
||||
],
|
||||
"maine coon": [
|
||||
"A photo of a pet maine coon. it is a large cat with a long body, thick fur, and a bushy tail. It is usually grayish-brown and black.",
|
||||
"A photo of a pet maine coon. it is a domestic cat that has a muscular body, a bushy tail, and large ears. It is reddish-brown in color.",
|
||||
"A photo of a pet maine coon. it has a broad forehead, high cheekbones, and a long, tapering tail. It's coat is long, thick, and in a range of colors.",
|
||||
"A photo of a pet maine coon. it has a thick neck, pointed face, and alert ears. It's coat is long, fluffy, and usually in a tabby pattern.",
|
||||
"A photo of a pet maine coon. it has a long body, thick fur, and a long tail. It's coat is brown with black stripes.",
|
||||
"A photo of a pet maine coon. it has a thick coat, long body, and a bushy tail.",
|
||||
"A photo of a pet maine coon. it has a thick neck, short face, and small ears. It's coat is long, straight, and in brown color.",
|
||||
"A photo of a pet maine coon. a large cat breed. It has a thick coat that is mostly brown with black stripes. It has a long face and ears.",
|
||||
"A photo of a pet maine coon. it has a large, muscular body, a long, shaggy coat, and a bushy tail.",
|
||||
"A photo of a pet maine coon. it has a thick coat, long face, and big ears."
|
||||
],
|
||||
"miniature pinscher": [
|
||||
"A photo of a pet miniature pinscher. it has a lean body, square head, and high-set ears. It's coat is short, smooth, and in a red color.",
|
||||
"A photo of a pet miniature pinscher. it has short coat, is black and tan in color, and has erect ears.",
|
||||
"A photo of a pet miniature pinscher. it has a thin neck, short face, and floppy ears. Its coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet miniature pinscher. it has an elongated body, rectangular head, and prick ears. It's coat is short, smooth, and in either red, tan, or black color.\"",
|
||||
"A photo of a pet miniature pinscher. it has short coat, erect ears and it is black in color.",
|
||||
"A photo of a pet miniature pinscher. it has thin neck, short face, pointy ears. It's coat is short, smooth, and in black and brown color.",
|
||||
"A photo of a pet miniature pinscher. it has small body, erect ears, and a docked tail. It has a glossy, smooth coat that is black and reddish brown in color.",
|
||||
"A photo of a pet miniature pinscher. it has small, delicate features. It's ears are erect and it has a smooth, short coat. This is a pet Boston terrier, it has a short, wide head and a square jaw. Its coat is short and smooth, and it",
|
||||
"A photo of a pet miniature pinscher. it has a small body, short limbs, and a pointed muzzle. Its coat is short, smooth, and in red color.",
|
||||
"A photo of a pet miniature pinscher. it has proud carriage, docked tail, and erect ears. It's coat is smooth, lustrous, and in black color."
|
||||
],
|
||||
"newfoundland": [
|
||||
"A photo of a pet newfoundland. it has thick neck, short face, floppy ears. It's coat is long, thick, and in black color.",
|
||||
"A photo of a pet newfoundland. it has a thick neck, short face, floppy ears. It's coat is short and in brindle color.",
|
||||
"A photo of a pet newfoundland. it has thick neck, long face, big droopy ears. It's coat is long, wavy, and in black color.",
|
||||
"A photo of a pet newfoundland. it has thick neck, short face, floppy ears. It's coat is long and in black color.",
|
||||
"A photo of a pet newfoundland. it has thick neck, short face, floppy ears. It's coat is longer, wavy, and in black color.",
|
||||
"A photo of a pet newfoundland. it has a broad neck, short legs, a broad face. Its coat is very long, straight, and dark brown.",
|
||||
"A photo of a pet newfoundland. it has floppy ears, wide eyes, and a thick coat.",
|
||||
"A photo of a pet newfoundland. it has thick neck, long face, blocky head. It's coat is thick, curly, and in black color.",
|
||||
"A photo of a pet newfoundland. it has thick neck, short face, floppy ears. It's coat is long, thick, and in black color.",
|
||||
"A photo of a pet newfoundland. it has a thick neck, short face, and ears that hang down. Its coat is thick, oily, and black."
|
||||
],
|
||||
"persian": [
|
||||
"A photo of a pet persian. it has long fur, and it's coat is white.",
|
||||
"A photo of a pet persian. it has a long, bushy coat in a tabby color. It has a long face, and its ears are pointed.",
|
||||
"A photo of a pet persian. it has a long face, fluffy coat, and its ears are upright.",
|
||||
"A photo of a pet persian. it has long fur, is white, and has blue eyes.",
|
||||
"A photo of a pet persian. it has thick coat, long face, and big eyes. Its coat is long, fluffy, and in beige color.",
|
||||
"A photo of a pet persian. it has a long, fluffy coat in white color.",
|
||||
"A photo of a pet persian. it has a thick coat, long face, and small ears. Its coat is long, thick, and can be in many different colors.",
|
||||
"A photo of a pet persian. it has a long neck, short face, long ears. Its coat is silky, long, and in a smoke color.",
|
||||
"A photo of a pet persian. it has thick coat, long face, and flat nose. It's coat is in himalayan color.",
|
||||
"A photo of a pet persian. it has a thick, long coat, and in solid white color."
|
||||
],
|
||||
"pomeranian": [
|
||||
"A photo of a pet pomeranian. it has thick fur, small face, pointed ears. It's coat is long, and in orange color.",
|
||||
"A photo of a pet pomeranian. it has thick neck, short face, pointy ears. It's coat is thick, fluffy, and in black color.",
|
||||
"A photo of a pet pomeranian. it has a thick double coat, a fox-like face, and pointed ears. It is small in size, and its coat can be in many different colors.",
|
||||
"A photo of a pet pomeranian. it has a thick double coat, small stature, and a fox-like face. It's coat is in orange sable color.",
|
||||
"A photo of a pet pomeranian. it has a thick coat, short face, and small, pointy ears. It comes in many colors, but the most popular is the black and white one.",
|
||||
"A photo of a pet pomeranian. it has a round head, pointed ears, and a dense coat.",
|
||||
"A photo of a pet pomeranian. it has a thickfur, small ears and a face. The coat is medium in length and in a light brown color.",
|
||||
"A photo of a pet pomeranian. it has a thick coat, small face, and pointed ears. It is white in color.",
|
||||
"A photo of a pet pomeranian. it has a round head, small ears, and a thick coat. The coat is usually white, but can also be cream, orange, brown, or black.",
|
||||
"A photo of a pet pomeranian. it has a thick coat, pointed ears, and a fox-like face."
|
||||
],
|
||||
"pug": [
|
||||
"A photo of a pet pug. it is small andhas a wrinkled face. It's coat is short and in fawn color.",
|
||||
"A photo of a pet pug. it has a short face, curly tail, and it is black in color.",
|
||||
"A photo of a pet pug. it has thin neck, short face, floppy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet pug. it has a short, stump of a tail, a pushed-in nose, and small, dark eyes. Its coat is short and in fawn color.",
|
||||
"A photo of a pet pug. it has short legs, a short nose, and big eyes. Its coat is smooth, soft, and in fawn color.",
|
||||
"A photo of a pet pug. it has a short face, small ears, and a flat nose. Its coat is short and in fawn color.",
|
||||
"A photo of a pet pug. it has thin neck, short face, floppy ears. It's coat is short and straight, and in fawn color.",
|
||||
"A photo of a pet pug. it has thick neck, short face, floppy ears. Its coat is short and in black color.",
|
||||
"A photo of a pet pug. it has a short snout, curly tail, and bulging eyes. Its coat is short, smooth, and in fawn color.",
|
||||
"A photo of a pet pug. it has a short coat that is either fawn or black in color. It has a flat face, and its ears are either erect or floppy."
|
||||
],
|
||||
"ragdoll": [
|
||||
"A photo of a pet ragdoll. it is a big, fluffy, blue eyed cat.",
|
||||
"A photo of a pet ragdoll. it has long neck, short face, pointy ears. It's coat is long, fluffy, and in seal color.",
|
||||
"A photo of a pet ragdoll. it has a long body, blue eyes, and a pointed face. It's coat is long and both straight and curly.",
|
||||
"A photo of a pet ragdoll. it has a thick coat that's in blue colorpoint. It has a medium-sized body and pointed ears.",
|
||||
"A photo of a pet ragdoll. it has a chubby face, big eyes, and a soft coat.",
|
||||
"A photo of a pet ragdoll. it has long neck, medium face, semi-erect ears. Its coat is long, silky, and blue.",
|
||||
"A photo of a pet ragdoll. it has a long body, semi-long face, and blue eyes. It's coat is long, fluffy, and in pointed color.",
|
||||
"A photo of a pet ragdoll. it has a long body, blue eyes, and a pointed face. Its coat is long, silky, and in seal color.",
|
||||
"A photo of a pet ragdoll. it has fluffy fur, and in blue color.",
|
||||
"A photo of a pet ragdoll. it has long fur, blue eyes, and a pointed face. It is a medium-sized cat."
|
||||
],
|
||||
"russian blue": [
|
||||
"A photo of a pet russian blue. it is a domestic cat breed with a thick double coat, green eyes, and a tidy and relatively small frame.",
|
||||
"A photo of a pet russian blue. it has lean body, long face, highset ears. It's coat is medium long, thick, and in blue color.",
|
||||
"A photo of a pet russian blue. it has a thick coat that is blue-grey in color, long body, and wedge-shaped head.",
|
||||
"A photo of a pet russian blue. it has long neck, short face, erect ears. It's coat is short, straight, and in gray color.",
|
||||
"A photo of a pet russian blue. it has short fur, thin tail, and is coal-black.",
|
||||
"A photo of a pet russian blue. it has short fur, and is light blue in color.",
|
||||
"A photo of a pet russian blue. it has slender body, long neck, triangular face, and green eyes. It's coat is long, dense, and glossy blue.",
|
||||
"A photo of a pet russian blue. it has medium-long fur, and is in blue color.",
|
||||
"A photo of a pet russian blue. it has a broad chest, thick fur, and a long tail.",
|
||||
"A photo of a pet russian blue. it has a long body, short legs, and a long tail. It's coat is short, dense, and in blue color."
|
||||
],
|
||||
"saint bernard": [
|
||||
"A photo of a pet saint bernard. it has thick fur, floppy ears, long face. It's coat is in white and brown, and it is very long.",
|
||||
"A photo of a pet saint bernard. its coat is long, thick, and in brindle color. It has a thick neck, long face, and prick ears.",
|
||||
"A photo of a pet saint bernard. it has a thick neck, short face, and floppy ears. It's coat is long, wavy, and in black and white color.",
|
||||
"A photo of a pet saint bernard. it has a thick coat, long face, and erect ears. It is usually a mixture of brown, white, and black.",
|
||||
"A photo of a pet saint bernard. it has a large head and body, short coat, and it is a working dog.",
|
||||
"A photo of a pet saint bernard. it has thick neck, short face, floppy ears. It's coat is long, thick, and in brindle color.",
|
||||
"A photo of a pet saint bernard. it has thin neck, short face, floppy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet saint bernard. it has a massive head, short coat, and webbed feet. It is a working dog breed.",
|
||||
"A photo of a pet saint bernard. it is a gentle giant. It has a thick, waterproof coat which helps protect it from the cold. It has a relaxed and patient personality.",
|
||||
"A photo of a pet saint bernard. it has short fur, short legs, and a long body. It is brown and white in color."
|
||||
],
|
||||
"samoyed": [
|
||||
"A photo of a pet samoyed. it has thick fur, it is white and it has a smiley face.",
|
||||
"A photo of a pet samoyed. it has a thick coat, and a fluffy tail.",
|
||||
"A photo of a pet samoyed. it has a furry face, furry ears, and a furry tail. It's coat is thick and white.",
|
||||
"A photo of a pet samoyed. it has thick coat, curled tail, and it is white in color.",
|
||||
"A photo of a pet samoyed. it has a thick coat, curled tail, and a face with a mask. It is all white.",
|
||||
"A photo of a pet samoyed. it has thick coat, long face, and curled tail.",
|
||||
"A photo of a pet samoyed. it has thick fur, which is white in color. It has a black nose, and its eyes are brown. It has a thick neck, and a small face.",
|
||||
"A photo of a pet samoyed. it has a thick coat, curled tail, and is in white color.",
|
||||
"A photo of a pet samoyed. it has a thick coat, long face, erect ears. It is white in color.",
|
||||
"A photo of a pet samoyed. it has a fluffy white coat, and is used to sledding."
|
||||
],
|
||||
"scottish terrier": [
|
||||
"A photo of a pet scottish terrier. it has short legs, wirey coat, and a long body. It's coat is black, white, and brown.",
|
||||
"A photo of a pet scottish terrier. it has a small, compact body. It's coat is medium length, wiry texture, and in black or gray color.",
|
||||
"A photo of a pet scottish terrier. it has a thick neck, short face, and erect ears. It's coat is harsh, wiry, and in black color.",
|
||||
"A photo of a pet scottish terrier. it has a rough coat, and a compact body. It is black with a white chest.",
|
||||
"A photo of a pet scottish terrier. it has a harsh double coat that is wiry to the touch. It has a small head, and dark, almond-shaped eyes. The coat is black and tan in color.",
|
||||
"A photo of a pet scottish terrier. which is a small dog. It has a short coat that is black and white. It has a long body and a short face.",
|
||||
"A photo of a pet scottish terrier. it has a thick neck, short stubby legs, and a short coat that is in black and brown color.",
|
||||
"A photo of a pet scottish terrier. it has a long neck, short face, erect ears. It's coat is harsh, wiry, and in black color.",
|
||||
"A photo of a pet scottish terrier. it has a wiry coat, and is in black color.",
|
||||
"A photo of a pet scottish terrier. it has a rough coat, in black and white color. It has a wedge shaped head, and pointed ears."
|
||||
],
|
||||
"shiba inu": [
|
||||
"A photo of a pet shiba inu. it has a thick coat that is red and white. It has a fox-like face and small, triangular ears.",
|
||||
"A photo of a pet shiba inu. it has a thick coat in red, black, and tan colors. It has a curled tail and pointed ears.",
|
||||
"A photo of a pet shiba inu. it has small, triangular eyes, and a black coat with white markings.",
|
||||
"A photo of a pet shiba inu. it has a thick coat, curled tail, and it is a red sesame color.",
|
||||
"A photo of a pet shiba inu. it has thin neck, short face, floppy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet shiba inu. it has fluffy coat, triangular ears, and a tail that curls over its back. It is brown and white in color.",
|
||||
"A photo of a pet shiba inu. it has curled tails, and thick fur. It is a working dog, used in Japan for centuries.",
|
||||
"A photo of a pet shiba inu. it has small narrow eyes, erect ears, and a curled tail. It's coat is medium length, fluffy, and in red color.",
|
||||
"A photo of a pet shiba inu. it has thin neck, short face, floppy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet shiba inu. it has a thick neck, fox-like face, and erect ears. It's coat is thick, fluffy, and in red sesame color."
|
||||
],
|
||||
"siamese": [
|
||||
"A photo of a pet siamese. it is a medium sized cat, with a long body and short legs. It has blue eyes and a Siamese coat, which is short and dense.",
|
||||
"A photo of a pet siamese. it has a long, thin body and face, and pointy ears. Its coat is long and in seal point color.",
|
||||
"A photo of a pet siamese. it has light-colored fur, blue eyes, and a triangular head.",
|
||||
"A photo of a pet siamese. it has long neck, triangular face, erect ears. It's coat is medium-length, silky, and in seal point color.",
|
||||
"A photo of a pet siamese. it has a long body, triangular head, and pointed ears. Its coat is long and silky, and in seal point color.",
|
||||
"A photo of a pet siamese. it has long body, short face, and pointy ears. It's coat is long, silky, and in seal color.",
|
||||
"A photo of a pet siamese. it has a thin neck, short face, and blue eyes. Its coat is short, straight, and in seal point color.",
|
||||
"A photo of a pet siamese. it has a long slim body, pointy ears, and almond shaped eyes. It's coat is short and in seal point color.",
|
||||
"A photo of a pet siamese. it has a long body, short legs, and a triangular head. It's coat is short, soft, and in seal color.",
|
||||
"A photo of a pet siamese. it has erect ears, and a long, tapering body. It's coat is short, fine, and in seal point color."
|
||||
],
|
||||
"sphynx": [
|
||||
"A photo of a pet sphynx. it is a hairless breed of cat. It has big ears, long legs, and a slender body.",
|
||||
"A photo of a pet sphynx. it is a bald, whiskerless cat. It has a wedge-shaped head and large, lemon-shaped eyes.",
|
||||
"A photo of a pet sphynx. it is a hairless cat with long legs, small ears, and a pronounced wedge-shaped head.",
|
||||
"A photo of a pet sphynx. it has no fur, wrinkled skin, and big ears.",
|
||||
"A photo of a pet sphynx. it has a wrinkled body and no fur. It is an indoor cat and does not like going outside.",
|
||||
"A photo of a pet sphynx. it is hairless, with wedge-shaped head, high cheekbones and large ears. It's body is medium-sized and muscular.",
|
||||
"A photo of a pet sphynx. it has no hair, wrinkled skin, short legs, and big ears.",
|
||||
"A photo of a pet sphynx. it has wrinkled skin, no fur, and typically a small, stocky build.This is a pet pug, it has a short, wrinkled muzzle, large, round eyes, and small, erect ears. Its coat is",
|
||||
"A photo of a pet sphynx. it is a hairless cat. It is medium size with a body that is tubular and long. It has triangle shaped head and small, pointy ears. Sphynx are known for being social and loving towards their owner.",
|
||||
"A photo of a pet sphynx. it has no fur, and is wrinkled."
|
||||
],
|
||||
"staffordshire bull terrier": [
|
||||
"A photo of a pet staffordshire bull terrier. which is a cross between the english bulldog and the english terrier.",
|
||||
"A photo of a pet staffordshire bull terrier. it has thick neck, short face, floppy ears. It's coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet staffordshire bull terrier. it has short face, big chest, and wide head. It's coat is short and in fawn color.",
|
||||
"A photo of a pet staffordshire bull terrier. it has a thick neck, a short face, and floppy ears. It's coat is short and in brindle color.",
|
||||
"A photo of a pet staffordshire bull terrier. it is a cross between the bulldog and the terrier. It has a short face, floppy ears, and a thick neck. The coat is short and in brindle color.",
|
||||
"A photo of a pet staffordshire bull terrier. it has short legs, a broad chest, and a short coat that is colored in brindle.",
|
||||
"A photo of a pet staffordshire bull terrier. it is a cross between a bulldog and a terrier.",
|
||||
"A photo of a pet staffordshire bull terrier. it has a thick neck, short face, and floppy ears. Its coat is short, straight, and in brindle color.",
|
||||
"A photo of a pet staffordshire bull terrier. it has short coat, thick neck, short face and erect ears. Its coat is black with white patches.",
|
||||
"A photo of a pet staffordshire bull terrier. it has muscular body, short coat and a broad head."
|
||||
],
|
||||
"wheaten terrier": [
|
||||
"A photo of a pet wheaten terrier. it has long neck, a wheat colored coat, and erect ears.",
|
||||
"A photo of a pet wheaten terrier. it has medium length coat, it is white with patches of brown on its head and body.",
|
||||
"A photo of a pet wheaten terrier. it has dense coat in wheat color, short face and ears.",
|
||||
"A photo of a pet wheaten terrier. it has a silky coat and a natural wheaten color. It is a medium sized dog. This is a pet toy poodle, it has a curly coat and is in apricot color.",
|
||||
"A photo of a pet wheaten terrier. it has a medium length coat that is straight and in a wheat color.",
|
||||
"A photo of a pet wheaten terrier. it has a thick neck and face with floppy ears. It's coat is thick, and in wheaten color.",
|
||||
"A photo of a pet wheaten terrier. it has a thick coat of fur that is reddish brown in color. It has a long body and legs, and its face is long and narrow. It has small, dark eyes, and its ears are erect and pointed.",
|
||||
"A photo of a pet wheaten terrier. it has a thick coat of hair that is reddish in color. It has a long head, and its ears hang down.",
|
||||
"A photo of a pet wheaten terrier. it has long coat that is soft and in wheaten color. It has a somewhat rectangular head, dark brown eyes, erect ears.",
|
||||
"A photo of a pet wheaten terrier. it has a round head, medium-size body, and round eyes. Its coat is soft, thick, and in wheaten color."
|
||||
],
|
||||
"yorkshire terrier": [
|
||||
"A photo of a pet yorkshire terrier. it has long, silky hair that is tan and black. It has a small face, and round eyes. It is a small dog.",
|
||||
"A photo of a pet yorkshire terrier. it has small, pointy ears, and a long, silky coat that is either tan or blue and tan.",
|
||||
"A photo of a pet yorkshire terrier. it has a long silky coat, in blue and tan color. It has a short face and ears.",
|
||||
"A photo of a pet yorkshire terrier. it has a small body, long coat, and pointed ears. It's coat is in black and tan color.",
|
||||
"A photo of a pet yorkshire terrier. it has long silky coat, small body, and triangular shaped head.",
|
||||
"A photo of a pet yorkshire terrier. it has long hair that is silky, straight, and in a light brown color.",
|
||||
"A photo of a pet yorkshire terrier. it has a long coat that is silky and in dark colors. It has small, pointy ears, and a long snout.",
|
||||
"A photo of a pet yorkshire terrier. it has a long coat that is silky and in tan color. It has a small head, and its ears stand erect.",
|
||||
"A photo of a pet yorkshire terrier. it has long silky coat, in parti-color. It is small in size, has a long snout, and perky ears.",
|
||||
"A photo of a pet yorkshire terrier. it has small body, short coat, and black and tan color."
|
||||
]
|
||||
}
|
||||
10194
gpt_file/stanford_cars_prompt.json
Normal file
20646
gpt_file/sun397_prompt.json
Normal file
5254
gpt_file/ucf101_prompt.json
Normal file
BIN
images/image_0001.jpg
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
images/image_0002.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
images/image_0003.jpg
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
images/image_0004.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
images/image_0005.jpg
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
images/image_0006.jpg
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
images/image_0007.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
images/image_0008.jpg
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
images/image_0009.jpg
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
images/image_0010.jpg
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
images/image_0011.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
images/image_0012.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
images/image_0013.jpg
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
images/image_0014.jpg
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
images/image_0015.jpg
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
images/image_0023.jpg
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
images/image_0024.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
images/image_0025.jpg
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
images/image_0026.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
images/image_0027.jpg
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
images/image_0028.jpg
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
images/image_0029.jpg
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
images/image_0030.jpg
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
images/image_0031.jpg
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
images/image_0032.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
images/image_0033.jpg
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
images/image_0034.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
images/image_0035.jpg
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
images/image_0036.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
images/image_0037.jpg
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
images/image_0038.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
images/image_0039.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
images/image_0040.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
images/image_0041.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
images/image_0042.jpg
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
images_2/image_0001.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
images_2/image_0002.jpg
Normal file
|
After Width: | Height: | Size: 12 KiB |