from time import time # get planer array library, numpy # pal = planer.core(numpy) # get planer array library, cupy pal = planer.core(cupy) img = io.imread('test.jpg') x = (img/255.0).transpose(2, 0, 1) x = x[None, :, :, :].astype('float32') x = pal.array(x) x = resize(x, (224, 224)) net = read_net('mobile') print('load done!') net(x) print('start timing!') start = time() for i in range(10): y = net(x) print('planer mobilenet-v1 time (x10):', time()-start) y = pal.argmax(y, axis=-1) rst = classes[int(y[0])] print('result:', rst) plt.imshow(img.astype('uint8')) plt.title(rst)
def load(lang='ch'): globals()['net'] = planer.read_net(root+'/openpose')
return resize(img, (h, w)) def normal(img): img = img.astype('float32') img.reshape((-1, 3))[:] -= pal.array([104, 117, 123]) return img img = io.imread('test.jpg') img_ = pal.array(img) x = normal(img_).transpose(2, 0, 1) x = makesize32(x[None, :, :, :]) # 2 files needed, hed.txt, hed.npy net = read_net('hed') y = net(x) net.timer = {} print('start timing!') start = time() for i in range(10): y = net(x) print('planer hed time (x10):', time() - start) run_time = (time() - start) / 10 for k in net.timer: print(k, net.timer[k]) y = pal.cpu(y) plt.subplot(121)
# get planer array library, numpy # get planer array library, cupy pal = planer.core(cupy) img = gravel() img = numpy.concatenate(([img], [img])) img = img.astype('float32') / 255 #img = numpy.zeros((2,1024,1024), 'float32') img_ = pal.array(img) x = img_[None, :, :, :] net = read_net('cellpose') print('load done!') y = net(x) net.timer = {} print('start timing!') start = time() for i in range(1): y = net(x) print('unet detect time x1:', time() - start) for k in net.timer: print(k, net.timer[k]) y = pal.cpu(y[0]) plt.subplot(131)
def load(): globals()['net'] = planer.read_net(root + '/face68key.onnx')
51: 'w', 52: 'x', 53: 'y', 54: 'z' } def greedy_search(raw, blank=0): max_id = raw.argmax(2).ravel() msk = max_id[1:] != max_id[:-1] max_id = max_id[1:][msk] return max_id[max_id != blank] # net = planer.onnx2planer('./crnn.onnx') net = planer.read_net('./crnn-ocr') x = page()[:40, :150].astype('float32') w = 48 * x.shape[1] // x.shape[0] x = planer.resize(x, (48, w)) x = (x - 0.5) / (90 / 255) x = x[None, None, :, :] net.timer = {} start = time() y = net(x) print(time() - start) for k in net.timer: print(k, net.timer[k])
yy1 = pal.maximum(y1[i], y1[order[1:]]) xx2 = pal.minimum(x2[i], x2[order[1:]]) yy2 = pal.minimum(y2[i], y2[order[1:]]) w = pal.maximum(0.0, xx2 - xx1 + 1) h = pal.maximum(0.0, yy2 - yy1 + 1) inter = w * h ovr = inter / (areas[i] + areas[order[1:]] - inter) inds = pal.where(ovr <= thresh)[0] order = order[inds + 1] return keep net = read_net('yolov3') y = net(x) net.timer = {} start = time() y = net(x) print('yolo-v3 time:', time() - start) for k in net.timer: print(k, net.timer[k]) plt.imshow(img[:, :, ::-1]) # get one result from the batch results bbox = post_process(y, anchors_all)[0] start = time()
def load(name='resnet'): globals()['net'] = planer.read_net(root+'/%s.onnx'%name) with open(root+'/imagenet_labs.json') as f: globals()['classes'] = json.load(f)
des *= np.array(img.shape[:2]).reshape(2, 1, 1) / 224 rst = planer.mapcoord(img.transpose(2, 0, 1), *des * 1) return rst.transpose(1, 2, 0).astype(np.uint8) # generate check board def check_board(shp, d=20): checkboard = np.zeros(shp, dtype=np.uint8) msk = np.tile([False] * d + [True] * d, 1000) checkboard[msk[:shp[0]]] += 128 checkboard[:, msk[:shp[1]]] += 128 return ((checkboard > 0) * 255).astype(np.uint8) if __name__ == '__main__': net = planer.read_net('./face_key') face = imread('./face.jpg') x = np.array(face.transpose(2, 0, 1)[None, :, :, :]) x = planer.resize(x, (224, 224)).astype(np.float32) start = time() y = net(x / 255) print(time() - start) rc = y.reshape(-1, 2)[:, ::-1] * 50 + 100 thin = flow_map(face, count_flow(rc, fac=-10)) fat = flow_map(face, count_flow(rc, fac=10)) grid = check_board(face.shape, 30) thin_grid = flow_map(grid, count_flow(rc, fac=-10))
# size to be 32x def makesize32(img): h, w = img.shape[-2:] w = w // 32 * 32 h = h // 32 * 32 return resize(img, (h, w)) img = io.imread('test.jpg')[:, :, ::-1] img_ = pal.array(img) x = normalize(img_).transpose(2, 0, 1)[None, :, :, :].copy() x = makesize32(x) # 2 files needed, craft.txt, craft.npy net = read_net('craft') print('load done!') y = net(x) net.timer = {} start = time() print('start timing!') for i in range(10): y = net(x) print('planer craft time (x10):', time() - start) runtime = (time() - start) / 10 for k in net.timer: print(k, net.timer[k])
def load(): globals()['net'] = planer.read_net(root+'/fba.onnx')
from matplotlib import pyplot as plt from time import time # get planer array library, numpy # pal = planer.core(numpy) # get planer array library, cupy pal = planer.core(numpy) img = io.imread('test.jpg')[:,:,:3] x = (img/255.0).transpose(2, 0, 1) x = x[None, :, :, :].astype('float32') x = pal.array(x) x = resize(x, (224, 224)) net = read_net('resnet18') print('load done!') y = net(x) ''' print('start timing!') net.timer={} start = time() for i in range(10): y = net(x) print('planer resnet18 time (x10):', time()-start) ''' y = pal.argmax(y, axis=-1) rst = classes[int(y[0])] for k in net.timer: print(k, net.timer[k])
def load(): globals()['net'] = planer.read_net(root + '/rvm_mobilenetv3.onnx')
def load(name='u2netp_general'): globals()['net'] = planer.read_net(root + '/%s.onnx' % name)
def load_model(names='cyto_0'): if isinstance(names, str): return read_net(root + '/models/' + names) return [read_net(root + '/models/' + i) for i in names]
import cupy import planer from planer import read_net, resize # get planer array library, numpy # pal = planer.core(numpy) # get planer array library, cupy pal = planer.core(cupy) img = io.imread('comic.png')[:, :, :3] x = (img / 255.0).transpose(2, 0, 1) x = x[None, :, :, :].astype('float32') x = pal.array(x) net = read_net('ESRGAN') print('load done!') y = net(x) print('start timing!') start = time() y = net(x) print('planer esrgan time:', time() - start) y = pal.cpu(y) plt.subplot(121) plt.imshow(img.astype('uint8')) plt.subplot(122) plt.imshow(y[0, :, :, :].transpose(1, 2, 0)) plt.show()