minor cleanups, yolo work
MODIFY
.github/workflows/test.yml
.github/workflows/test.yml
@@ -13,7 +13,7 @@ jobs:
- name: Install SLOCCount
run: sudo apt-get install sloccount
- name: Check <1000 lines
- run: sloccount tinygrad test examples; if [ $(sloccount tinygrad | sed -n 's/.*Total Physical Source Lines of Code (SLOC)[ ]*= \([^ ]*\).*/\1/p' | tr -d ',') -gt 1000 ]; then exit 1; fi
+ run: sloccount tinygrad test examples extra; if [ $(sloccount tinygrad | sed -n 's/.*Total Physical Source Lines of Code (SLOC)[ ]*= \([^ ]*\).*/\1/p' | tr -d ',') -gt 1000 ]; then exit 1; fi
linter:
name: Indentation Linter

MODIFY
examples/yolov5.py
examples/yolov5.py
@@ -5,27 +5,29 @@ from extra.utils import fetch, my_unpickle
if __name__ == "__main__":
dat = fetch('https://github.com/ultralytics/yolov5/releases/download/v3.0/yolov5s.pt')
- #import torch
- #td = torch.load(io.BytesIO(dat))
- #print(td)
+ #dat = fetch('https://github.com/ultralytics/yolov5/releases/download/v3.0/yolov5m.pt')
import zipfile
fp = zipfile.ZipFile(io.BytesIO(dat))
#fp.printdir()
data = fp.read('archive/data.pkl')
- #import pickletools
- #pickletools.dis(io.BytesIO(data))
-
+ # yolo specific
ret, out = my_unpickle(io.BytesIO(data))
- print(dir(ret['model']))
- for m in ret['model']._modules['model']:
- print(m)
- print(m._modules.keys())
+ d = ret['model'].yaml
+ for i, (f, n, m, args) in enumerate(d['backbone'] + d['head']):
+ tm = ret['model']._modules['model'][i]
+ print(i, f, n, m, args, tm._modules.keys())
+ # Focus, Conv, BottleneckCSP, SPP, Concat, Detect
+ #for k,v in tm._modules.items():
+ # print(" ", k, v)
+ if m in "Focus":
+ conv = tm._modules['conv']
+ print(" ", conv._modules)
+ if m in "Conv":
+ conv, bn = tm._modules['conv'], tm._modules['bn']
+ print(" ", conv)
+ #print(bn)
+
- """
- weights = fake_torch_load(data)
- for k,v in weights:
- print(k)
- """

MODIFY
tinygrad/optim.py
tinygrad/optim.py
# sorted in order of increasing complexity
-
-import numpy as np
from tinygrad.tensor import Tensor
class Optimizer:
@@ -25,7 +23,7 @@ class RMSprop(Optimizer):
super().__init__(params)
self.lr, self.decay, self.eps = lr, decay, eps
- self.v = [Tensor(np.zeros(t.shape, dtype=np.float32), device=params[0].device, requires_grad=False) for t in self.params]
+ self.v = [Tensor.zeros(*t.shape, device=params[0].device, requires_grad=False) for t in self.params]
def step(self):
for i, t in enumerate(self.params):
@@ -37,8 +35,8 @@ class Adam(Optimizer):
super().__init__(params)
self.lr, self.b1, self.b2, self.eps, self.t = lr, b1, b2, eps, 0
- self.m = [Tensor(np.zeros(t.shape, dtype=np.float32), device=params[0].device, requires_grad=False) for t in self.params]
- self.v = [Tensor(np.zeros(t.shape, dtype=np.float32), device=params[0].device, requires_grad=False) for t in self.params]
+ self.m = [Tensor.zeros(*t.shape, device=params[0].device, requires_grad=False) for t in self.params]
+ self.v = [Tensor.zeros(*t.shape, device=params[0].device, requires_grad=False) for t in self.params]
def step(self):
self.t = self.t + 1

minor cleanups, yolo work