mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-24 02:14:17 +00:00
prevent race condition, external yolo test for now
This commit is contained in:
parent
0f58c4c648
commit
3a2a500e90
3 changed files with 10 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import pickle
|
||||
import numpy as np
|
||||
from tqdm import tqdm
|
||||
from tinygrad.tensor import Tensor
|
||||
import tempfile
|
||||
from tinygrad.helpers import prod, getenv
|
||||
|
||||
def fetch(url):
|
||||
|
|
@ -21,10 +21,10 @@ def download_file(url, fp, skip_if_exists=False):
|
|||
r = requests.get(url, stream=True)
|
||||
assert r.status_code == 200
|
||||
progress_bar = tqdm(total=int(r.headers.get('content-length', 0)), unit='B', unit_scale=True, desc=url)
|
||||
with open(fp+".tmp", "wb") as f:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as f:
|
||||
for chunk in r.iter_content(chunk_size=16384):
|
||||
progress_bar.update(f.write(chunk))
|
||||
os.rename(fp+".tmp", fp)
|
||||
os.rename(f.name, fp)
|
||||
|
||||
def my_unpickle(fb0):
|
||||
key_prelookup = {}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import io
|
||||
import unittest
|
||||
from extra.utils import fetch
|
||||
from PIL import Image
|
||||
|
||||
class TestUtils(unittest.TestCase):
|
||||
def test_fetch_bad_http(self):
|
||||
|
|
@ -11,5 +13,10 @@ class TestUtils(unittest.TestCase):
|
|||
def test_fetch_small(self):
|
||||
assert(len(fetch('https://google.com'))>0)
|
||||
|
||||
def test_fetch_img(self):
|
||||
img = fetch("https://media.istockphoto.com/photos/hen-picture-id831791190")
|
||||
pimg = Image.open(io.BytesIO(img))
|
||||
assert pimg.size == (705, 1024)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue