Skip to content

Commit df05cbc

Browse files
committed
modification about the op
1 parent 40611f6 commit df05cbc

5 files changed

Lines changed: 37 additions & 7 deletions

File tree

infCNN/OpLib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ def forward(self, x):
8282
return self._pool_forward(x, self.maxpool, self.size, self.stride)
8383

8484

85+
relu = ReLU()
86+
flatten = Flatten()
87+
sigmoid = Sigmoid()
88+
softmax = Softmax()
89+
maxpool = MaxPool()

infCNN/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .LayerLib import *
22
from .OpLib import *
3+
from .numpy_extend import *

infCNN/numpy_extend.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import numpy as np
2+
3+
4+
# up 2x featuremap, NxCxHxW -> NxCx2Hx2W
5+
def up2x(fm):
6+
shape2x = np.array(fm.shape)
7+
shape2x[-2:] *= 2
8+
9+
fm2x = np.zeros(shape2x)
10+
fm2x[:, :, ::2, ::2] = fm
11+
fm2x[:, :, 1::2, 1::2] = fm
12+
13+
return fm2x
14+
15+
16+
# up 4x featuremap, NxCxHxW -> NxCx4Hx4W
17+
def up4x(fm):
18+
fm4x = up2x(up2x(fm))
19+
return fm4x
20+
21+
if __name__ == "__main__":
22+
img = np.random.randn(2, 3, 100, 100)
23+
img2x = up4x(img)
24+
print(img.shape, img2x.shape)
25+
26+
print(np.sum(img - img2x[:, :, ::4, ::4]))
27+
28+

net.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
# infCNN layer
44
from infCNN import Conv2d, Dense
55
# infCNN op
6-
from infCNN import ReLU, Flatten, MaxPool, Softmax
6+
from infCNN import relu, flatten, maxpool, softmax
77
from time import time
88

9-
# op
10-
relu = ReLU()
11-
flatten = Flatten()
12-
maxpool = MaxPool()
13-
softmax = Softmax()
14-
159
class LeNet():
1610
def __init__(self):
1711
self.conv1 = Conv2d(1, 6, 5, 1)

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Example is shown in ```net.py```, which shows the inference of a LeNet CNN. Weig
1212
The training on pytorch is regular, which can be seen in ```train/``` folder. The weights of CNN are exported to ```.mat``` file.
1313

1414

15+
#### Plugins for ImagePy
16+
The plugin is in ```plgs/``` folder
1517

1618
#### References
1719

0 commit comments

Comments
 (0)