package to simplify few-shot object detection
Project description
fsdetection
fsdetection is a Python package for few-shot object detection, inspired by the simplicity and flexibility of Hugging Face libraries. With fsdetection
, you can quickly experiment with few-shot learning for object detection tasks, easily integrate it with popular frameworks, and customize detection models with minimal data.
Features
- Few-Shot Object Detection: Fine-tune object detection models with only a few examples per class.
- Cross-Domain Adaptation: Effortlessly adapt models to new domains.
- Modular Design: Build and customize models with a clean, intuitive API.
- Pre-trained Models: Access a range of pre-trained models as a starting point for your tasks.
Installation
Install fsdetection
directly from PyPI:
pip install fsdetection
LoRA script implementation
https://github.com/Baijiong-Lin/LoRA-Torch
def replace_lora(model, module_name, rank):
for sub_module_name in model._modules:
cuurent_module_name = sub_module_name if module_name == "" else module_name + "." + sub_module_name
if len(model._modules[sub_module_name]._modules) > 1:
replace_lora(model._modules[sub_module_name], cuurent_module_name, rank=rank)
else:
if isinstance(model._modules[sub_module_name], nn.Conv2d):
model._modules[sub_module_name] = LoraConv2d(
in_channels=model._modules[sub_module_name].in_channels,
out_channels=model._modules[sub_module_name].out_channels,
kernel_size=model._modules[sub_module_name].kernel_size[0],
stride=model._modules[sub_module_name].stride,
padding=model._modules[sub_module_name].padding,
padding_mode=model._modules[sub_module_name].padding_mode,
dilation=model._modules[sub_module_name].dilation,
groups=model._modules[sub_module_name].groups,
bias=model._modules[sub_module_name].bias is not None,
norm=model._modules[sub_module_name].norm,
r=rank
).to('cuda')
elif isinstance(model._modules[sub_module_name], nn.MultiheadAttention):
model._modules[sub_module_name] = lora.MultiheadAttention(
model._modules[sub_module_name].embed_dim,
model._modules[sub_module_name].num_heads,
dropout=model._modules[sub_module_name].dropout,
r=rank
).to('cuda')
elif isinstance(model._modules[sub_module_name], nn.Linear):
model._modules[sub_module_name] = lora.Linear(
model._modules[sub_module_name].in_features,
model._modules[sub_module_name].out_features,
bias=model._modules[sub_module_name].bias is not None,
r=rank
).to('cuda')
else:
if len(model._modules[sub_module_name]._modules) > 0:
replace_lora(model._modules[sub_module_name], cuurent_module_name, rank=rank)
class LoraTrainer(FineTuningTrainer):
def __init__(self, cfg):
super().__init__(cfg)
@classmethod
def build_model(cls, cfg, is_finetuned=False):
model = super().build_model(cfg, is_finetuned)
replace_lora(model, "", rank=cfg.FINETUNE.LORA.RANK)
return model
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fsdetection-0.0.5.tar.gz
(15.0 kB
view details)
Built Distribution
File details
Details for the file fsdetection-0.0.5.tar.gz
.
File metadata
- Download URL: fsdetection-0.0.5.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
f9b0afdfd05bca7321e25dd21ae576e101b31686bf0ea7b0f1dac91fc17e91b9
|
|
MD5 |
f25c2329ed28a5f1c45e63227797e648
|
|
BLAKE2b-256 |
e2d45a21acfc26e2df5c709a08e8242dccfdb7efa6631dbfcc052f01e6693bcd
|
File details
Details for the file fsdetection-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: fsdetection-0.0.5-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
18bdeb68fc95c750ed42c834d9598ad51cd9b332176501aa2a4b049c2513b755
|
|
MD5 |
f3f35c894766ed28572240d9ffedae9c
|
|
BLAKE2b-256 |
f166be0b2c2bc328f7f2cf49965aa775a998b34f288c54074178876aec4924ea
|