Datasets:
Download source/legacy_project/code/pilot.py from Ethosoft/RefSeg-CA: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/datasets/Ethosoft/RefSeg-CA/resolve/main/source/legacy_project/code/pilot.py
- Command line
-
hf download hf://datasets/Ethosoft/RefSeg-CA/source/legacy_project/code/pilot.py
-
curl -L -o pilot.py https://huggingface.co/datasets/Ethosoft/RefSeg-CA/resolve/main/source/legacy_project/code/pilot.py
1.37 kB
| from pathlib import Path | |
| import os,time,json | |
| t=time.time() | |
| print('starting imports',flush=True) | |
| import torch | |
| from transformers import CLIPSegProcessor,CLIPSegForImageSegmentation,AutoProcessor,AutoModelForZeroShotObjectDetection,SamModel,SamProcessor | |
| from PIL import Image,ImageDraw | |
| root=Path(__file__).resolve().parents[1] | |
| print('imports complete',time.time()-t,torch.__version__,flush=True) | |
| assert torch.cuda.is_available() | |
| device='cuda';modeldir=root/'assets/models/clipseg' | |
| p=CLIPSegProcessor.from_pretrained(modeldir,local_files_only=True);m=CLIPSegForImageSegmentation.from_pretrained(modeldir,local_files_only=True).to(device).eval() | |
| im=Image.new('RGB',(320,320),'white');ImageDraw.Draw(im).ellipse((60,60,230,230),fill='red') | |
| x=p(text=['a red circle'],images=[im],return_tensors='pt',padding=True).to(device) | |
| with torch.inference_mode():y=m(**x,interpolate_pos_encoding=True).logits | |
| torch.cuda.synchronize() | |
| result={'job_id':os.environ.get('SLURM_JOB_ID'),'device':torch.cuda.get_device_name(0),'torch':torch.__version__,'shape':list(y.shape),'finite':bool(torch.isfinite(y).all()),'max_probability':float(y.sigmoid().max()),'elapsed_seconds':time.time()-t,'purpose':'Infrastructure smoke test on a constructed image; not a benchmark result'} | |
| (root/'results/pilot.json').write_text(json.dumps(result,indent=2));print(json.dumps(result,indent=2),flush=True) | |