Spaces:
Running
Running
model files
Browse files- .idea/.gitignore +3 -0
- .idea/ACL-SSL-zeroshot-demo.iml +8 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +1 -1
- pretrain/BEATs_iter3_plus_AS2M_finetuned_on_AS2M_cpt2.pt +3 -0
- pretrain/Param_best.pth +3 -0
- pretrain/README.md +1 -0
- util.py +67 -0
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
.idea/ACL-SSL-zeroshot-demo.iml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="inheritedJdk" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
</module>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="Black">
|
4 |
+
<option name="sdkName" value="Python 3.10" />
|
5 |
+
</component>
|
6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
7 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/ACL-SSL-zeroshot-demo.iml" filepath="$PROJECT_DIR$/.idea/ACL-SSL-zeroshot-demo.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="" vcs="Git" />
|
5 |
+
</component>
|
6 |
+
</project>
|
app.py
CHANGED
@@ -34,7 +34,7 @@ def main():
|
|
34 |
# seg = out_dict['heatmap'][j:j + 1]
|
35 |
# seg_image = ((1 - seg.squeeze().detach().cpu().numpy()) * 255).astype(np.uint8)
|
36 |
# seg_image = Image.fromarray(seg_image)
|
37 |
-
heatmap_image = cv2.applyColorMap(np.array(seg_image), cv2.COLORMAP_JET)
|
38 |
# overlaid_image = cv2.addWeighted(np.array(original_image), 0.5, heatmap_image, 0.5, 0)
|
39 |
|
40 |
|
|
|
34 |
# seg = out_dict['heatmap'][j:j + 1]
|
35 |
# seg_image = ((1 - seg.squeeze().detach().cpu().numpy()) * 255).astype(np.uint8)
|
36 |
# seg_image = Image.fromarray(seg_image)
|
37 |
+
# heatmap_image = cv2.applyColorMap(np.array(seg_image), cv2.COLORMAP_JET)
|
38 |
# overlaid_image = cv2.addWeighted(np.array(original_image), 0.5, heatmap_image, 0.5, 0)
|
39 |
|
40 |
|
pretrain/BEATs_iter3_plus_AS2M_finetuned_on_AS2M_cpt2.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e5815275a04b6885e7b8af63d120b29bffae2cd2225cf4915e1ec6d819d3022c
|
3 |
+
size 363145291
|
pretrain/Param_best.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5a376017ac43da53a88a4e6ec269053454bca41ee61b96cef7c800dd3100e58f
|
3 |
+
size 29122795
|
pretrain/README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
For pretrain model
|
util.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
|
3 |
+
import numpy as np
|
4 |
+
import random
|
5 |
+
import os
|
6 |
+
from typing import Tuple, Optional
|
7 |
+
|
8 |
+
|
9 |
+
def get_prompt_template(mode: str = 'default') -> Tuple[str, int, int]:
|
10 |
+
'''
|
11 |
+
Generate a prompt template based on the specified mode.
|
12 |
+
|
13 |
+
Args:
|
14 |
+
mode (str, optional): The mode for selecting the prompt template. Default is 'default'.
|
15 |
+
|
16 |
+
Returns:
|
17 |
+
Tuple[str, int, int]: A tuple containing the generated prompt template, the position of the placeholder '{}',
|
18 |
+
and the length of the prompt.
|
19 |
+
|
20 |
+
Notes:
|
21 |
+
If the mode is 'random', a random prompt template is chosen from a predefined list.
|
22 |
+
'''
|
23 |
+
prompt_template = 'A photo of {}'
|
24 |
+
|
25 |
+
if mode == 'random':
|
26 |
+
prompt_templates = [
|
27 |
+
'a photo of a {}', 'a photograph of a {}', 'an image of a {}', '{}',
|
28 |
+
'a cropped photo of a {}', 'a good photo of a {}', 'a photo of one {}',
|
29 |
+
'a bad photo of a {}', 'a photo of the {}', 'a photo of {}', 'a blurry photo of a {}',
|
30 |
+
'a picture of a {}', 'a photo of a scene where {}'
|
31 |
+
]
|
32 |
+
prompt_template = random.choice(prompt_templates)
|
33 |
+
|
34 |
+
# Calculate prompt length and text position
|
35 |
+
prompt_length = 1 + len(prompt_template.split(' ')) + 1 - 1 # eos, sos => 1 + 1, {} => -1
|
36 |
+
text_pos_at_prompt = 1 + prompt_template.split(' ').index('{}')
|
37 |
+
|
38 |
+
return prompt_template, text_pos_at_prompt, prompt_length
|
39 |
+
|
40 |
+
|
41 |
+
# Reproducibility
|
42 |
+
def fix_seed(seed: int = 0) -> None:
|
43 |
+
'''
|
44 |
+
Set seeds for random number generators to ensure reproducibility.
|
45 |
+
|
46 |
+
Args:
|
47 |
+
seed (int, optional): The seed value. Default is 0.
|
48 |
+
'''
|
49 |
+
np.random.seed(seed)
|
50 |
+
random.seed(seed)
|
51 |
+
torch.manual_seed(seed)
|
52 |
+
torch.cuda.manual_seed_all(seed) # multi-GPU
|
53 |
+
torch.backends.cudnn.deterministic = True
|
54 |
+
torch.backends.cudnn.benchmark = False
|
55 |
+
os.environ['PYTHONHASHSEED'] = str(seed)
|
56 |
+
|
57 |
+
|
58 |
+
def seed_worker(worker_id: int) -> None:
|
59 |
+
'''
|
60 |
+
Set a seed for a worker process to ensure reproducibility in PyTorch DataLoader.
|
61 |
+
|
62 |
+
Args:
|
63 |
+
worker_id (int): The ID of the worker process.
|
64 |
+
'''
|
65 |
+
worker_seed = torch.initial_seed() % 2**32
|
66 |
+
np.random.seed(worker_seed)
|
67 |
+
random.seed(worker_seed)
|