-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
53 lines (46 loc) · 1.34 KB
/
Copy path__init__.py
File metadata and controls
53 lines (46 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""SHIELD -- non-invasive visual contrastive decoding with feature enhancement.
Quick start::
import shield
model = shield.wrap(model, tokenizer, caption_file="captions.jsonl")
shield_kw = model.shield_prepare(image, image_tensor, image_file)
output = model.generate(input_ids, **shield_kw, do_sample=True, max_new_tokens=1024)
"""
from .wrapper import wrap, DEFAULT_PARAMS
from .attack import cw_attack, perform_clip_attack, pgd_attack
from .caption import (
find_text_by_image,
load_captions,
prepare_caption_inputs,
process_caption,
)
from .clip_utils import clear_clip_cache, get_clip_text_features, load_clip_model
from .feature import (
clear_bias_cache,
compute_shield_image_weights,
get_bias,
map_text_segments,
maximize_weight_difference,
)
from .noise import add_diffusion_noise
from .sampling import enable_shield_sampling
__all__ = [
"wrap",
"DEFAULT_PARAMS",
"cw_attack",
"pgd_attack",
"perform_clip_attack",
"load_clip_model",
"clear_clip_cache",
"get_clip_text_features",
"load_captions",
"find_text_by_image",
"process_caption",
"prepare_caption_inputs",
"compute_shield_image_weights",
"maximize_weight_difference",
"map_text_segments",
"get_bias",
"clear_bias_cache",
"add_diffusion_noise",
"enable_shield_sampling",
]