MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / loader_process

Function loader_process

examples/mlperf/dataloader.py:39–70  ·  view source on GitHub ↗
(q_in, q_out, X:Tensor, seed)

Source from the content-addressed store, hash-verified

37 del indices[i]
38
39def loader_process(q_in, q_out, X:Tensor, seed):
40 import signal
41 signal.signal(signal.SIGINT, lambda _, __: exit(0))
42
43 from extra.datasets.imagenet import center_crop, preprocess_train
44 from PIL import Image
45
46 with Context(DEBUG=0):
47 while (_recv := q_in.get()) is not None:
48 idx, fn, val = _recv
49 if fn is not None:
50 img = Image.open(fn)
51 img = img.convert('RGB') if img.mode != "RGB" else img
52
53 if val:
54 # eval: 76.08%, load in 0m7.366s (0m5.301s with simd)
55 # sudo apt-get install libjpeg-dev
56 # CC="cc -mavx2" pip install -U --force-reinstall pillow-simd
57 img = center_crop(img)
58 img = np.array(img)
59 else:
60 # reseed rng for determinism
61 if seed is not None:
62 np.random.seed(seed * 2 ** 10 + idx)
63 random.seed(seed * 2 ** 10 + idx)
64 img = preprocess_train(img)
65 else:
66 # pad data with training mean
67 img = np.tile(np.array([[[123.68, 116.78, 103.94]]], dtype=np.uint8), (224, 224, 1))
68 X[idx].flatten().assign(img.tobytes())
69 q_out.put(idx)
70 q_out.put(None)
71
72def batch_load_resnet(batch_size=64, val=False, shuffle=True, seed=None, pad_first_batch=False):
73 from extra.datasets.imagenet import get_train_files, get_val_files

Callers

nothing calls this directly

Calls 10

ContextClass · 0.90
center_cropFunction · 0.90
preprocess_trainFunction · 0.90
convertMethod · 0.80
flattenMethod · 0.80
putMethod · 0.80
signalMethod · 0.45
getMethod · 0.45
openMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…