sunhill commited on
Commit
ec09ccb
·
1 Parent(s): 25133b6

add SPICE dependency jar

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.jar filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+
204
+ # Ruff stuff:
205
+ .ruff_cache/
206
+
207
+ # PyPI configuration file
208
+ .pypirc
209
+
210
+ # Marimo
211
+ marimo/_static/
212
+ marimo/_lsp/
213
+ __marimo__/
214
+
215
+ # Streamlit
216
+ .streamlit/secrets.toml
217
+
218
+ # Custom additions
219
+ lib/stanford*.jar
220
+ !lib/
221
+ **/.DS_Store
.spice.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import json
4
+ import numpy as np
5
+ import tempfile
6
+
7
+ # Assumes spice.jar is in the same directory as spice.py. Change as needed.
8
+ SPICE_JAR = "spice-1.0.jar"
9
+ TEMP_DIR = "tmp"
10
+ CACHE_DIR = "cache"
11
+
12
+
13
+ class Spice:
14
+ """
15
+ Main Class to compute the SPICE metric
16
+ """
17
+
18
+ def float_convert(self, obj):
19
+ try:
20
+ return float(obj)
21
+ except (ValueError, TypeError):
22
+ return np.nan
23
+
24
+ def compute_score(self, gts, res):
25
+ assert sorted(gts.keys()) == sorted(res.keys())
26
+ imgIds = sorted(gts.keys())
27
+
28
+ # Prepare temp input file for the SPICE scorer
29
+ input_data = []
30
+ for id in imgIds:
31
+ hypo = res[id]
32
+ ref = gts[id]
33
+
34
+ # Sanity check.
35
+ assert type(hypo) is list
36
+ assert len(hypo) == 1
37
+ assert type(ref) is list
38
+ assert len(ref) >= 1
39
+
40
+ input_data.append({"image_id": id, "test": hypo[0], "refs": ref})
41
+
42
+ cwd = os.path.dirname(os.path.abspath(__file__))
43
+ temp_dir = os.path.join(cwd, TEMP_DIR)
44
+ if not os.path.exists(temp_dir):
45
+ os.makedirs(temp_dir)
46
+ in_file = tempfile.NamedTemporaryFile(delete=False, dir=temp_dir)
47
+ json.dump(input_data, in_file, indent=2)
48
+ in_file.close()
49
+
50
+ # Start job
51
+ out_file = tempfile.NamedTemporaryFile(delete=False, dir=temp_dir)
52
+ out_file.close()
53
+ cache_dir = os.path.join(cwd, CACHE_DIR)
54
+ if not os.path.exists(cache_dir):
55
+ os.makedirs(cache_dir)
56
+ spice_cmd = [
57
+ "java",
58
+ "-jar",
59
+ "-Xmx8G",
60
+ SPICE_JAR,
61
+ in_file.name,
62
+ "-cache",
63
+ cache_dir,
64
+ "-out",
65
+ out_file.name,
66
+ "-subset",
67
+ "-silent",
68
+ ]
69
+ subprocess.check_call(spice_cmd, cwd=os.path.dirname(os.path.abspath(__file__)))
70
+
71
+ # Read and process results
72
+ with open(out_file.name) as data_file:
73
+ results = json.load(data_file)
74
+ os.remove(in_file.name)
75
+ os.remove(out_file.name)
76
+
77
+ imgId_to_scores = {}
78
+ spice_scores = []
79
+ for item in results:
80
+ imgId_to_scores[item["image_id"]] = item["scores"]
81
+ spice_scores.append(self.float_convert(item["scores"]["All"]["f"]))
82
+ average_score = np.mean(np.array(spice_scores))
83
+ scores = []
84
+ for image_id in imgIds:
85
+ # Convert none to NaN before saving scores over subcategories
86
+ score_set = {}
87
+ for category, score_tuple in imgId_to_scores[image_id].iteritems():
88
+ score_set[category] = {
89
+ k: self.float_convert(v) for k, v in score_tuple.items()
90
+ }
91
+ scores.append(score_set)
92
+ return average_score, scores
93
+
94
+ def method(self):
95
+ return "SPICE"
get_stanford_models.sh ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env sh
2
+ # This script downloads the Stanford CoreNLP models.
3
+
4
+ CORENLP=stanford-corenlp-full-2015-12-09
5
+ SPICELIB=lib
6
+
7
+ DIR="$( cd "$(dirname "$0")" ; pwd -P )"
8
+ cd $DIR
9
+
10
+ echo "Downloading..."
11
+
12
+ wget http://nlp.stanford.edu/software/$CORENLP.zip
13
+
14
+ echo "Unzipping..."
15
+
16
+ mkdir -p .tmp
17
+ unzip $CORENLP.zip -d .tmp/
18
+ mv .tmp/$CORENLP/stanford-corenlp-3.6.0.jar $SPICELIB/
19
+ mv .tmp/$CORENLP/stanford-corenlp-3.6.0-models.jar $SPICELIB/
20
+ rm -f stanford-corenlp-full-2015-12-09.zip
21
+ rm -rf .tmp
22
+
23
+ echo "Done."
lib/Meteor-1.5.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:014a3627d277a6f4ba5b44a20733f8dff28bbb428204c36abfda56565658ba09
3
+ size 6318623
lib/SceneGraphParser-1.0.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83a1b7c3f896dd135f9539ba41d65b155827dfc312893bfd5bb835c9f9ae310a
3
+ size 164039
lib/ejml-0.23.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12d44e81fdd661ad2aac6384511facf3d8fa003c3ce8d9cec5f22827d1819a26
3
+ size 301506
lib/fst-2.47.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c871febc859cf72dbed1c6c1eebc5600c3d93c3e986feccf4623cc5086098cc
3
+ size 380882
lib/guava-19.0.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58d4cc2e05ebb012bbac568b032f75623be1cb6fb096f3c60c72a86f7f057de4
3
+ size 2308517
lib/hamcrest-core-1.3.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9
3
+ size 45024
lib/jackson-core-2.5.3.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9a900c30c702d371be2d3714938dfa6de616599c8eb39f8e3cf7aedd62dfd32
3
+ size 229998
lib/javassist-3.19.0-GA.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d19c1ef43ccd9cb1b39466bb2f1c8e45c2b6752f1e13a3dfb60096543d1791fa
3
+ size 749499
lib/json-simple-1.1.1.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e69696892b88b41c55d49ab2fdcc21eead92bf54acc588c0050596c3b75199c
3
+ size 23931
lib/junit-4.12.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a
3
+ size 314932
lib/lmdbjni-0.4.6.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4e8c51eb4ef05abe57d2187e76f5c335e4ef16d8503329eb7dbc5ae7a90529c
3
+ size 85980
lib/lmdbjni-linux64-0.4.6.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b7773db873aaeec399a50113c0a4e121df0eff5e724607f7bc8171452107d94
3
+ size 385952
lib/lmdbjni-osx64-0.4.6.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d66778037b5689e7c6daf22a7140722f2085da4ae479bceda4a4be487d55460
3
+ size 106300
lib/lmdbjni-win64-0.4.6.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:969c6aa59893b82856a6832da640672b0f23f1d72f70d7b04296c71970d75b79
3
+ size 72671
lib/objenesis-2.4.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:090416e160a7e398f79e0149a7b05ef328b1843898a34e08c1cc170128d326d0
3
+ size 51287
lib/slf4j-api-1.7.12.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0aee9a77a4940d72932b0d0d9557793f872e66a03f598e473f45e7efecdccf99
3
+ size 32127
lib/slf4j-simple-1.7.21.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a20179cc3ded2d7e2f5def4ccb34b2d0836e2f8c9e79352a6babd6a6559cc8e0
3
+ size 10905
spice-1.0.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c6a73ae6dd108667047c1818707590413934dcb9f1a62cef6469059b41b3d59
3
+ size 19751099