|
1 | 1 | import os |
2 | 2 | from collections.abc import Sequence |
| 3 | +from importlib import resources |
| 4 | +from pathlib import Path |
3 | 5 |
|
4 | 6 | import numpy as np |
5 | 7 | import torch |
|
8 | 10 | from ..utils import normalize, to_3HW |
9 | 11 | from ..utils.image import _imread |
10 | 12 |
|
11 | | -_path = os.path.dirname(__file__) |
| 13 | +# _path = os.path.dirname(__file__) |
12 | 14 |
|
13 | | -QRCODE96 = os.path.join(_path, 'qr-96.jpg') |
| 15 | +def _get_path(fname:str): |
| 16 | + return Path(str(resources.files("visualbench").joinpath("data", fname))) |
| 17 | + |
| 18 | +QRCODE96 = _get_path('qr-96.jpg') |
14 | 19 | """QR code that links to my github account""" |
15 | 20 |
|
16 | | -ATTNGRAD96 = os.path.join(_path, 'attngrad-96.png') |
| 21 | +ATTNGRAD96 = _get_path('attngrad-96.png') |
17 | 22 | """Piece of gradient of some model from transformers library except I don't remember which one""" |
18 | 23 |
|
19 | | -SANIC96 = os.path.join(_path, 'sanic-96.jpg') |
| 24 | +SANIC96 = _get_path('sanic-96.jpg') |
20 | 25 | """is an 8 year old image from my images folder and I think it is a screenshot from one of the sanic games""" |
21 | 26 |
|
22 | | -FROG96 = os.path.join(_path, 'frog-96.png') |
| 27 | +FROG96 = _get_path('frog-96.png') |
23 | 28 | """frame from https://www.youtube.com/@NinjaFrog777/videos""" |
24 | 29 |
|
25 | | -WEEVIL96 = os.path.join(_path, 'weevil-96.png') |
| 30 | +WEEVIL96 = _get_path('weevil-96.png') |
26 | 31 | """is from http://growingorganic.com/ipm-guide/weevils/""" |
27 | 32 |
|
28 | | -TEST96 = os.path.join(_path, 'test-96.jpg') |
| 33 | +TEST96 = _get_path('test-96.jpg') |
29 | 34 | """this was generated in like 2012 ago by google doodle generator and its still my favourite image and it is called test""" |
30 | 35 |
|
31 | | -MAZE96 = os.path.join(_path, 'maze-96.png') |
| 36 | +MAZE96 = _get_path('maze-96.png') |
32 | 37 | """a generic maze""" |
33 | 38 |
|
34 | | -TEXT96 = os.path.join(_path, 'text-96.png') |
| 39 | +TEXT96 = _get_path('text-96.png') |
35 | 40 | """lorem ipsum from lorem ipsum text""" |
36 | 41 |
|
37 | | -GEOM96 = os.path.join(_path, 'geometry-96.png') |
| 42 | +GEOM96 = _get_path('geometry-96.png') |
38 | 43 | """CC0 image from wikicommons, SORRY I CAN'T FIND THE LINK ANYMORE!!!""" |
39 | 44 |
|
40 | | -RUBIC96 = os.path.join(_path, 'rubic-96.png') |
| 45 | +RUBIC96 = _get_path('rubic-96.png') |
41 | 46 | """is from https://speedsolving.fandom.com/wiki/Rubik%27s_Cube?file=Rubik%27s_Cube_transparency.png""" |
42 | 47 |
|
43 | | -SPIRAL96 = os.path.join(_path, 'spiral-96.png') |
| 48 | +SPIRAL96 = _get_path('spiral-96.png') |
44 | 49 | """A colorful spiral""" |
45 | 50 |
|
46 | | -BIANG96 = os.path.join(_path, 'biang-96.png') |
| 51 | +BIANG96 = _get_path('biang-96.png') |
47 | 52 | """apparently its the hardest hieroglyph and it is from https://commons.wikimedia.org/wiki/File:Bi%C3%A1ng_%28regular_script%29.svg""" |
48 | 53 |
|
49 | | -EMOJIS96 = os.path.join(_path, 'emojis-96.png') |
| 54 | +EMOJIS96 = _get_path('emojis-96.png') |
50 | 55 | """some random emojis""" |
51 | 56 |
|
52 | | -GRID96 = os.path.join(_path, 'grid-96.png') |
| 57 | +GRID96 = _get_path('grid-96.png') |
53 | 58 | """Grid of black and white cells""" |
54 | 59 |
|
55 | 60 | def get_qrcode(): |
@@ -165,7 +170,7 @@ def get_ill_conditioned(size: int | tuple[int,int], cond:float=1e17): |
165 | 170 |
|
166 | 171 | def get_font_dict(dtype=torch.bool, device=None): |
167 | 172 | """returns a dictionary which maps letters, numbers and +-*/|. to 3x3 binary images.""" |
168 | | - path = os.path.join(_path, '3x3 font.jpeg') |
| 173 | + path = _get_path('3x3 font.jpeg') |
169 | 174 | image = to_3HW(_imread(path).float()).mean(0) |
170 | 175 | image = torch.where(image > 128, 1, 0).contiguous().to(dtype=dtype, device=device) |
171 | 176 |
|
|
0 commit comments