diff --git a/handlers/svg-open-street-map/requirements.txt b/handlers/svg-open-street-map/requirements.txt index 276608bb..de4ea5cc 100644 Binary files a/handlers/svg-open-street-map/requirements.txt and b/handlers/svg-open-street-map/requirements.txt differ diff --git a/preprocessors/ner/Dockerfile b/preprocessors/ner/Dockerfile index 28b8ba2a..87afb18e 100644 --- a/preprocessors/ner/Dockerfile +++ b/preprocessors/ner/Dockerfile @@ -1,12 +1,11 @@ -FROM ubuntu:20.04 +FROM python:3.11-bookworm -ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/ +ENV JAVA_HOME=/usr/lib/jvm/default-java RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ - openjdk-8-jdk \ - python3-pip \ - gcc \ + build-essential \ + default-jre-headless \ git \ curl \ && apt-get clean && \ diff --git a/preprocessors/ner/clipscore.py b/preprocessors/ner/clipscore.py index 57e5d2b8..c54ce91d 100644 --- a/preprocessors/ner/clipscore.py +++ b/preprocessors/ner/clipscore.py @@ -13,12 +13,9 @@ import clip import torch from PIL import Image -from sklearn.preprocessing import normalize from torchvision.transforms import Compose, Resize, CenterCrop, ToTensor, Normalize -import torch import tqdm import numpy as np -import sklearn.preprocessing import collections import os import pathlib @@ -35,6 +32,12 @@ from pycocoevalcap.spice.spice import Spice +def normalize_rows(values: np.ndarray) -> np.ndarray: + """Normalize a 2D float array row-wise while leaving zero-norm rows as zeros.""" + norms = np.linalg.norm(values, axis=1, keepdims=True) + return np.divide(values, norms, out=np.zeros_like(values), where=norms != 0) + + def get_all_metrics(refs, cands, return_per_cap=False): metrics = [] names = [] @@ -212,14 +215,14 @@ def get_clip_score(model, images, candidates, device, w=2.5): #as of numpy 1.21, normalize doesn't work properly for float16 if version.parse(np.__version__) < version.parse('1.21'): - images = sklearn.preprocessing.normalize(images, axis=1) - candidates = sklearn.preprocessing.normalize(candidates, axis=1) + images = normalize_rows(images) + candidates = normalize_rows(candidates) else: warnings.warn( 'due to a numerical instability, new numpy normalization is slightly different than paper results. ' 'to exactly replicate paper results, please use numpy version less than 1.21, e.g., 1.20.3.') - images = images / np.sqrt(np.sum(images**2, axis=1, keepdims=True)) - candidates = candidates / np.sqrt(np.sum(candidates**2, axis=1, keepdims=True)) + images = normalize_rows(images) + candidates = normalize_rows(candidates) per = w*np.clip(np.sum(images * candidates, axis=1), 0, None) return np.mean(per), per, candidates @@ -241,15 +244,15 @@ def get_refonlyclipscore(model, references, candidates, device): flattened_refs = extract_all_captions(flattened_refs, model, device) if version.parse(np.__version__) < version.parse('1.21'): - candidates = sklearn.preprocessing.normalize(candidates, axis=1) - flattened_refs = sklearn.preprocessing.normalize(flattened_refs, axis=1) + candidates = normalize_rows(candidates) + flattened_refs = normalize_rows(flattened_refs) else: warnings.warn( 'due to a numerical instability, new numpy normalization is slightly different than paper results. ' 'to exactly replicate paper results, please use numpy version less than 1.21, e.g., 1.20.3.') - candidates = candidates / np.sqrt(np.sum(candidates**2, axis=1, keepdims=True)) - flattened_refs = flattened_refs / np.sqrt(np.sum(flattened_refs**2, axis=1, keepdims=True)) + candidates = normalize_rows(candidates) + flattened_refs = normalize_rows(flattened_refs) cand_idx2refs = collections.defaultdict(list) for ref_feats, cand_idx in zip(flattened_refs, flattened_refs_idxs): diff --git a/preprocessors/ner/requirements.txt b/preprocessors/ner/requirements.txt index 75816f2b..b2a3a946 100644 --- a/preprocessors/ner/requirements.txt +++ b/preprocessors/ner/requirements.txt @@ -2,14 +2,13 @@ bs4==0.0.1 imgkit==1.2.2 nltk==3.7 gunicorn==23.0.0 -pillow==12.1.1 -torch==1.13.1 +pillow==12.2.0 +torch==2.6.0 tqdm~=4.66.3 -torchvision==0.8.2 -clip-by-openai==1.1 -scikit-learn==1.1.2 +torchvision==0.21.0 packaging==21.3 jsonschema==4.23.0 Flask==3.1.3 pycocoevalcap==1.2 -git+https://github.com/openai/CLIP \ No newline at end of file +# Pin the tested CLIP commit used for the Python 3.11-compatible NER build. +git+https://github.com/openai/CLIP@d05afc436d78f1c48dc0dbf8e5980a9d471f35f6 diff --git a/preprocessors/ner/test_clipscore.py b/preprocessors/ner/test_clipscore.py new file mode 100644 index 00000000..d66b4fab --- /dev/null +++ b/preprocessors/ner/test_clipscore.py @@ -0,0 +1,23 @@ +import unittest + +import numpy as np + +from clipscore import normalize_rows + + +class NormalizeRowsTest(unittest.TestCase): + def test_normalizes_rows(self): + values = np.array([[3.0, 4.0], [5.0, 12.0]]) + normalized = normalize_rows(values) + expected = np.array([[0.6, 0.8], [5.0 / 13.0, 12.0 / 13.0]]) + np.testing.assert_allclose(normalized, expected) + + def test_preserves_zero_rows(self): + values = np.array([[0.0, 0.0], [0.0, 2.0]]) + normalized = normalize_rows(values) + expected = np.array([[0.0, 0.0], [0.0, 1.0]]) + np.testing.assert_allclose(normalized, expected) + + +if __name__ == "__main__": + unittest.main() diff --git a/services/espnet-tts-fr/requirements.txt b/services/espnet-tts-fr/requirements.txt index e6a7091a..3ec47b74 100644 --- a/services/espnet-tts-fr/requirements.txt +++ b/services/espnet-tts-fr/requirements.txt @@ -1,6 +1,6 @@ espnet==202207 espnet_model_zoo==0.1.7 -Flask==3.1.3 +Flask==2.2.5 gunicorn==23.0.0 jsonschema==4.4.0 parallel_wavegan==0.5.5 diff --git a/services/espnet-tts/requirements.txt b/services/espnet-tts/requirements.txt index c5e004de..7790747a 100644 --- a/services/espnet-tts/requirements.txt +++ b/services/espnet-tts/requirements.txt @@ -1,6 +1,6 @@ espnet==0.10.0 espnet_model_zoo==0.1.7 -Flask==3.1.3 +Flask==2.2.5 gunicorn==23.0.0 jsonschema==4.4.0 parallel_wavegan==0.5.4