-
Notifications
You must be signed in to change notification settings - Fork 3
/
testPyPixelShuffleLayer.py
44 lines (28 loc) · 999 Bytes
/
testPyPixelShuffleLayer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy as np
import sys
import os
def runNet(input_blob, net, output_blob):
net.blobs['data'].data[...] = input_blob
output = net.forward() # run once before timing to set up memory
return output[output_blob][:]
if __name__ == "__main__":
model_def = sys.argv[1]
caffe_root = './'
if os.path.isdir(caffe_root):
sys.path.insert(0, caffe_root + 'python')
try:
import caffe
caffe.set_mode_cpu()
except ImportError:
raise ImportError(caffe_root + " doesn't appear to be the caffe root")
net = caffe.Net(model_def, caffe.TRAIN)
"""
# Test it with (in **ipython**)
run path/to/pythonScript path/to/prototxt
a = np.arange(1*18*30*30).reshape((1,18,30,30))
s = runNet(a, net, 'shuf')
# s should have a shape of (1,2,90,90)
# Backward pass of s should give a
u = net.backward(**{net.outputs[0]: s})
# u will have a shape of (1, 18, 30, 30)
"""