Skip to content

Commit 2f280b9

Browse files
committed
adding hed demo
1 parent 790ab9a commit 2f280b9

5 files changed

Lines changed: 141 additions & 0 deletions

File tree

demo/hed_edge_detector/hed.txt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
graph(%input : Float(1, 3, 200, 200),
2+
%moduleVggOne.0.weight : Float(64, 3, 3, 3),
3+
%moduleVggOne.0.bias : Float(64),
4+
%moduleVggOne.2.weight : Float(64, 64, 3, 3),
5+
%moduleVggOne.2.bias : Float(64),
6+
%moduleVggTwo.1.weight : Float(128, 64, 3, 3),
7+
%moduleVggTwo.1.bias : Float(128),
8+
%moduleVggTwo.3.weight : Float(128, 128, 3, 3),
9+
%moduleVggTwo.3.bias : Float(128),
10+
%moduleVggThr.1.weight : Float(256, 128, 3, 3),
11+
%moduleVggThr.1.bias : Float(256),
12+
%moduleVggThr.3.weight : Float(256, 256, 3, 3),
13+
%moduleVggThr.3.bias : Float(256),
14+
%moduleVggThr.5.weight : Float(256, 256, 3, 3),
15+
%moduleVggThr.5.bias : Float(256),
16+
%moduleVggFou.1.weight : Float(512, 256, 3, 3),
17+
%moduleVggFou.1.bias : Float(512),
18+
%moduleVggFou.3.weight : Float(512, 512, 3, 3),
19+
%moduleVggFou.3.bias : Float(512),
20+
%moduleVggFou.5.weight : Float(512, 512, 3, 3),
21+
%moduleVggFou.5.bias : Float(512),
22+
%moduleVggFiv.1.weight : Float(512, 512, 3, 3),
23+
%moduleVggFiv.1.bias : Float(512),
24+
%moduleVggFiv.3.weight : Float(512, 512, 3, 3),
25+
%moduleVggFiv.3.bias : Float(512),
26+
%moduleVggFiv.5.weight : Float(512, 512, 3, 3),
27+
%moduleVggFiv.5.bias : Float(512),
28+
%moduleScoreOne.weight : Float(1, 64, 1, 1),
29+
%moduleScoreOne.bias : Float(1),
30+
%moduleScoreTwo.weight : Float(1, 128, 1, 1),
31+
%moduleScoreTwo.bias : Float(1),
32+
%moduleScoreThr.weight : Float(1, 256, 1, 1),
33+
%moduleScoreThr.bias : Float(1),
34+
%moduleScoreFou.weight : Float(1, 512, 1, 1),
35+
%moduleScoreFou.bias : Float(1),
36+
%moduleScoreFiv.weight : Float(1, 512, 1, 1),
37+
%moduleScoreFiv.bias : Float(1),
38+
%moduleCombine.0.weight : Float(1, 5, 1, 1),
39+
%moduleCombine.0.bias : Float(1)):
40+
%39 : Float(1, 64, 200, 200) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%input, %moduleVggOne.0.weight, %moduleVggOne.0.bias), scope: Network/Sequential[moduleVggOne]/Conv2d[0]
41+
%40 : Float(1, 64, 200, 200) = onnx::Relu(%39), scope: Network/Sequential[moduleVggOne]/ReLU[1]
42+
%41 : Float(1, 64, 200, 200) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%40, %moduleVggOne.2.weight, %moduleVggOne.2.bias), scope: Network/Sequential[moduleVggOne]/Conv2d[2]
43+
%42 : Float(1, 64, 200, 200) = onnx::Relu(%41), scope: Network/Sequential[moduleVggOne]/ReLU[3]
44+
%43 : Float(1, 64, 100, 100) = onnx::MaxPool[kernel_shape=[2, 2], pads=[0, 0, 0, 0], strides=[2, 2]](%42), scope: Network/Sequential[moduleVggTwo]/MaxPool2d[0]
45+
%44 : Float(1, 128, 100, 100) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%43, %moduleVggTwo.1.weight, %moduleVggTwo.1.bias), scope: Network/Sequential[moduleVggTwo]/Conv2d[1]
46+
%45 : Float(1, 128, 100, 100) = onnx::Relu(%44), scope: Network/Sequential[moduleVggTwo]/ReLU[2]
47+
%46 : Float(1, 128, 100, 100) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%45, %moduleVggTwo.3.weight, %moduleVggTwo.3.bias), scope: Network/Sequential[moduleVggTwo]/Conv2d[3]
48+
%47 : Float(1, 128, 100, 100) = onnx::Relu(%46), scope: Network/Sequential[moduleVggTwo]/ReLU[4]
49+
%48 : Float(1, 128, 50, 50) = onnx::MaxPool[kernel_shape=[2, 2], pads=[0, 0, 0, 0], strides=[2, 2]](%47), scope: Network/Sequential[moduleVggThr]/MaxPool2d[0]
50+
%49 : Float(1, 256, 50, 50) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%48, %moduleVggThr.1.weight, %moduleVggThr.1.bias), scope: Network/Sequential[moduleVggThr]/Conv2d[1]
51+
%50 : Float(1, 256, 50, 50) = onnx::Relu(%49), scope: Network/Sequential[moduleVggThr]/ReLU[2]
52+
%51 : Float(1, 256, 50, 50) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%50, %moduleVggThr.3.weight, %moduleVggThr.3.bias), scope: Network/Sequential[moduleVggThr]/Conv2d[3]
53+
%52 : Float(1, 256, 50, 50) = onnx::Relu(%51), scope: Network/Sequential[moduleVggThr]/ReLU[4]
54+
%53 : Float(1, 256, 50, 50) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%52, %moduleVggThr.5.weight, %moduleVggThr.5.bias), scope: Network/Sequential[moduleVggThr]/Conv2d[5]
55+
%54 : Float(1, 256, 50, 50) = onnx::Relu(%53), scope: Network/Sequential[moduleVggThr]/ReLU[6]
56+
%55 : Float(1, 256, 25, 25) = onnx::MaxPool[kernel_shape=[2, 2], pads=[0, 0, 0, 0], strides=[2, 2]](%54), scope: Network/Sequential[moduleVggFou]/MaxPool2d[0]
57+
%56 : Float(1, 512, 25, 25) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%55, %moduleVggFou.1.weight, %moduleVggFou.1.bias), scope: Network/Sequential[moduleVggFou]/Conv2d[1]
58+
%57 : Float(1, 512, 25, 25) = onnx::Relu(%56), scope: Network/Sequential[moduleVggFou]/ReLU[2]
59+
%58 : Float(1, 512, 25, 25) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%57, %moduleVggFou.3.weight, %moduleVggFou.3.bias), scope: Network/Sequential[moduleVggFou]/Conv2d[3]
60+
%59 : Float(1, 512, 25, 25) = onnx::Relu(%58), scope: Network/Sequential[moduleVggFou]/ReLU[4]
61+
%60 : Float(1, 512, 25, 25) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%59, %moduleVggFou.5.weight, %moduleVggFou.5.bias), scope: Network/Sequential[moduleVggFou]/Conv2d[5]
62+
%61 : Float(1, 512, 25, 25) = onnx::Relu(%60), scope: Network/Sequential[moduleVggFou]/ReLU[6]
63+
%62 : Float(1, 512, 12, 12) = onnx::MaxPool[kernel_shape=[2, 2], pads=[0, 0, 0, 0], strides=[2, 2]](%61), scope: Network/Sequential[moduleVggFiv]/MaxPool2d[0]
64+
%63 : Float(1, 512, 12, 12) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%62, %moduleVggFiv.1.weight, %moduleVggFiv.1.bias), scope: Network/Sequential[moduleVggFiv]/Conv2d[1]
65+
%64 : Float(1, 512, 12, 12) = onnx::Relu(%63), scope: Network/Sequential[moduleVggFiv]/ReLU[2]
66+
%65 : Float(1, 512, 12, 12) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%64, %moduleVggFiv.3.weight, %moduleVggFiv.3.bias), scope: Network/Sequential[moduleVggFiv]/Conv2d[3]
67+
%66 : Float(1, 512, 12, 12) = onnx::Relu(%65), scope: Network/Sequential[moduleVggFiv]/ReLU[4]
68+
%67 : Float(1, 512, 12, 12) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%66, %moduleVggFiv.5.weight, %moduleVggFiv.5.bias), scope: Network/Sequential[moduleVggFiv]/Conv2d[5]
69+
%68 : Float(1, 512, 12, 12) = onnx::Relu(%67), scope: Network/Sequential[moduleVggFiv]/ReLU[6]
70+
%69 : Float(1, 1, 200, 200) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1]](%42, %moduleScoreOne.weight, %moduleScoreOne.bias), scope: Network/Conv2d[moduleScoreOne]
71+
%70 : Float(1, 1, 100, 100) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1]](%47, %moduleScoreTwo.weight, %moduleScoreTwo.bias), scope: Network/Conv2d[moduleScoreTwo]
72+
%71 : Float(1, 1, 50, 50) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1]](%54, %moduleScoreThr.weight, %moduleScoreThr.bias), scope: Network/Conv2d[moduleScoreThr]
73+
%72 : Float(1, 1, 25, 25) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1]](%61, %moduleScoreFou.weight, %moduleScoreFou.bias), scope: Network/Conv2d[moduleScoreFou]
74+
%73 : Float(1, 1, 12, 12) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1]](%68, %moduleScoreFiv.weight, %moduleScoreFiv.bias), scope: Network/Conv2d[moduleScoreFiv]
75+
%74 : Tensor = onnx::Constant[value= 1 1 1 1 [ Variable[CPUType]{4} ]](), scope: Network
76+
%75 : Float(1, 1, 200, 200) = onnx::Upsample[mode="linear"](%69, %74), scope: Network
77+
%76 : Tensor = onnx::Constant[value= 1 1 2 2 [ Variable[CPUType]{4} ]](), scope: Network
78+
%77 : Float(1, 1, 200, 200) = onnx::Upsample[mode="linear"](%70, %76), scope: Network
79+
%78 : Tensor = onnx::Constant[value= 1 1 4 4 [ Variable[CPUType]{4} ]](), scope: Network
80+
%79 : Float(1, 1, 200, 200) = onnx::Upsample[mode="linear"](%71, %78), scope: Network
81+
%80 : Tensor = onnx::Constant[value= 1 1 8 8 [ Variable[CPUType]{4} ]](), scope: Network
82+
%81 : Float(1, 1, 200, 200) = onnx::Upsample[mode="linear"](%72, %80), scope: Network
83+
%82 : Tensor = onnx::Constant[value= 1.0000 1.0000 16.6667 16.6667 [ Variable[CPUType]{4} ]](), scope: Network
84+
%83 : Float(1, 1, 200, 200) = onnx::Upsample[mode="linear"](%73, %82), scope: Network
85+
%84 : Float(1, 5, 200, 200) = onnx::Concat[axis=1](%75, %77, %79, %81, %83), scope: Network
86+
%85 : Float(1, 1, 200, 200) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1]](%84, %moduleCombine.0.weight, %moduleCombine.0.bias), scope: Network/Sequential[moduleCombine]/Conv2d[0]
87+
%output : Float(1, 1, 200, 200) = onnx::Sigmoid(%85), scope: Network/Sequential[moduleCombine]/Sigmoid[1]
88+
return (%output)
89+

demo/hed_edge_detector/main.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from cnnumpy import read_onnx
2+
import numpy as np
3+
from matplotlib import pyplot as plt
4+
from skimage import io, transform
5+
from time import time
6+
7+
8+
# size to be 8x
9+
def makesize8(img):
10+
h, w = img.shape[:2]
11+
w = (w//32 + 0)*32
12+
h = (h//32 + 0)*32
13+
img = transform.resize(img, (h, w), preserve_range=True)
14+
return img
15+
16+
def normal(img):
17+
img = img.copy()
18+
img[:, :, 0] -= 104
19+
img[:, :, 1] -= 117
20+
img[:, :, 2] -= 123
21+
return img.astype('float32')
22+
23+
img = io.imread('test.jpg')
24+
img = makesize8(img)
25+
x = normal(img).transpose(2, 0, 1)[None, :, :, :].copy()
26+
27+
28+
# 2 files needed, hed.txt, hed.npy
29+
net = read_onnx('hed')
30+
y = net(x)
31+
start = time()
32+
y = net(x)
33+
print('craft detect time:', time()-start)
34+
35+
plt.subplot(121)
36+
plt.imshow(img.astype('uint8'))
37+
# edge map
38+
plt.subplot(122)
39+
plt.imshow(y[0, 0, :, :])
40+
plt.title('edge map')
41+
42+
plt.show()
43+
44+
45+
46+

demo/hed_edge_detector/rst.png

117 KB
Loading

demo/hed_edge_detector/test.jpg

8.95 KB
Loading

demo/readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ Demo for scene text detector with model [CRAFT](https://github.com/clovaai/CRAFT
66
Run ```python main.py``` inside folder ```craft_text_detector```. 3 files (same level folder with ```main.py```) are needed (craft.txt, [craft.npy](), [craft_np.npy]())
77
The detected result is shown as following:
88
![](https://raw.githubusercontent.com/Image-Py/cnnumpy/master/demo/craft_text_detector/rst.png)
9+
10+
## HED edge detector
11+
Demo for edge detector with model HED. Run ```python main.py``` inside folder ```hed_edge_detector```. 2 files (same level folder with ```main.py```) are needed (hed.txt, [hed.npy]())
12+
The detected result is shown as following:
13+
![](https://raw.githubusercontent.com/Image-Py/cnnumpy/master/demo/hed_edge_detector/rst.png)
14+

0 commit comments

Comments
 (0)