okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0479b72e9
main
1#!/usr/bin/env python3 2"""Makes the picture test set of the own vision tower (Pillow only, deterministic). 3 4python tools/vision/own/make_test_images.py <out dir> 5 6The three pictures of tools/qwen35/pictures are copied as they are; the rest is drawn: small, odd aspect ratios, sizes that are not multiples of 732, a very large one (the resize path), the same picture as JPEG / BMP / GIF, grayscale, RGBA and palette PNGs, and a photo-like one (gradients + 8noise). Nothing here is large enough to matter in the repo, and nothing is committed: the folder is made when a check runs. 9""" 10import os 11import shutil 12import sys 13 14from PIL import Image ,ImageDraw ,ImageFilter ,ImageFont 15 16HERE = os .path .dirname (os .path .abspath (__file__ )) 17PICS = os .path .join (HERE ,".." ,".." ,"qwen35" ,"pictures" ) 18 19 20def font (size ): 21for name in ("DejaVuSans-Bold.ttf" ,"arialbd.ttf" ,"Arial Bold.ttf" ,"LiberationSans-Bold.ttf" ): 22try : 23return ImageFont .truetype (name ,size ) 24except OSError : 25pass 26return ImageFont .load_default () 27 28 29def scene (w ,h ,text ,seed = 0 ): 30"""A canvas with a few coloured shapes and a line of text, scaled to the size (so small and large pictures show the same things).""" 31im = Image .new ("RGB" , (w ,h ), (245 ,245 ,235 )) 32d = ImageDraw .Draw (im ) 33m = min (w ,h ) 34cols = [(220 ,40 ,40 ), (40 ,90 ,220 ), (30 ,160 ,70 ), (240 ,190 ,20 )] 35for i ,c in enumerate (cols ): 36x0 = int (w * (0.08 + 0.22 * i )) 37y0 = int (h * (0.15 + 0.1 * (i % 2 ))) 38r = max (2 ,int (m * 0.16 )) 39if i % 2 == 0 : 40d .ellipse ([x0 ,y0 ,x0 + r ,y0 + r ],fill = c ) 41else : 42d .rectangle ([x0 ,y0 ,x0 + r ,y0 + r ],fill = c ) 43d .text ((int (w * 0.06 ),int (h * 0.62 )),text ,fill = (20 ,20 ,20 ),font = font (max (8 ,int (m * 0.18 )))) 44return im 45 46 47def photo (w ,h ): 48"""Gradients plus noise, blurred a little: a photo-like picture with no flat areas.""" 49base = Image .merge ("RGB" , [Image .linear_gradient ("L" ).resize ((w ,h )), 50Image .linear_gradient ("L" ).rotate (90 ).resize ((w ,h )), 51Image .linear_gradient ("L" ).rotate (45 ,expand = False ).resize ((w ,h ))]) 52noise = Image .effect_noise ((w ,h ),40 ).convert ("RGB" ) 53out = Image .blend (base ,noise ,0.25 ).filter (ImageFilter .GaussianBlur (1.2 )) 54d = ImageDraw .Draw (out ) 55d .ellipse ([w * 0.3 ,h * 0.3 ,w * 0.7 ,h * 0.7 ],outline = (255 ,255 ,255 ),width = max (2 ,w // 100 )) 56return out 57 58 59def main (): 60if len (sys .argv )!= 2 : 61sys .exit (__doc__ ) 62out = sys .argv [1 ] 63os .makedirs (out ,exist_ok = True ) 64for n in ("shapes.png" ,"code4217.png" ,"big1024.png" ): 65shutil .copyfile (os .path .join (PICS ,n ),os .path .join (out ,n )) 66shapes = Image .open (os .path .join (PICS ,"shapes.png" )).convert ("RGB" ) 67save = lambda im ,n ,** kw :im .save (os .path .join (out ,n ),** kw )# noqa: E731 68save (scene (64 ,48 ,"Hi" ),"tiny_64x48.png" ) 69save (scene (90 ,1000 ,"TALL" ),"tall_90x1000.png" ) 70save (scene (1000 ,90 ,"WIDE strip" ),"wide_1000x90.png" ) 71save (scene (33 ,517 ,"odd" ),"odd_33x517.png" ) 72save (scene (999 ,777 ,"999 x 777" ),"odd_999x777.png" ) 73save (scene (333 ,333 ,"333" ),"odd_333x333.png" ) 74save (photo (1600 ,1200 ),"photo_1600x1200.jpg" ,quality = 90 ) 75save (scene (4000 ,3000 ,"HUGE 4000x3000" ),"huge_4000x3000.png" ) 76save (scene (8000 ,500 ,"HUGE 8000x500" ),"huge_8000x500.png" ) 77# pictures for the largest image-token limit the app allows (settings: vision_tokens up to 16,384 -> 65,536 patches); not part of the usual gate list 78save (scene (4096 ,4096 ,"LIMIT 4096" ),"limit_4096x4096.png" )# exactly 16,384 tokens at that limit 79save (scene (7000 ,5000 ,"LIMIT 7000x5000" ),"limit_7000x5000.png" )# more than 16,384 tokens: resized down to the limit 80save (shapes ,"shapes.jpg" ,quality = 90 ) 81save (shapes ,"shapes.bmp" ) 82save (shapes .convert ("P" ,palette = Image .ADAPTIVE ,colors = 64 ),"shapes_p.gif" ) 83save (shapes .convert ("L" ),"shapes_gray.png" ) 84rgba = shapes .convert ("RGBA" ) 85rgba .putalpha (Image .linear_gradient ("L" ).resize (shapes .size )) 86save (rgba ,"shapes_rgba.png" ) 87save (shapes .convert ("P" ,palette = Image .ADAPTIVE ,colors = 32 ),"shapes_pal.png" ) 88"wrote %d pictures to %s" % (len (os .listdir (out )),out )) 89 90 91if __name__ == "__main__" : 92main ()