-
Notifications
You must be signed in to change notification settings - Fork 2
/
cnn_single.py
executable file
·31 lines (26 loc) · 1.4 KB
/
cnn_single.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
#!/usr/bin/python
import Renascence
def main():
producer = Renascence.init(["./libAbstract_learning.xml"])
gd = producer.load('ALGradientMethod', './res/cnn/lenet.json')
print gd
#gd = producer.load('ALGradientMethod', './res/cnn/softmax.json')
trainMerge = producer.load('ALFloatMatrix', '../../machine_exam/handset/train.txt');
trainX = producer.build('MatrixLinear(MatrixCrop(x0, x1, x2), x3, x4)').run(producer.merge(trainMerge, 1.0, -1.0, 1.0/255.0, 0.0))
trainX.save('output/handset.trainX.txt')
trainY = producer.build('MatrixCrop(x0, x1, x2)').run(producer.merge(trainMerge, 0.0, 0.0))
trainY.save('output/handset.trainY.txt')
p = producer.build('ParameterInit(x0)').run(gd)
print trainX,trainY,gd,p
mergeM = producer.build('GDMatrixPrepare(x0, x1, x2)').run(producer.merge(trainX, trainY, gd))
mergeM.save('output/handset.m')
p = producer.build('GDCompute(x0, x1, x2)').run(producer.merge(mergeM, gd, p))
p.save('output/handset.p')
#p = producer.load('ALFloatMatrix', 'output/pieces/parameters/ALFloatMatrix_0')
#print p
predictX = producer.load('ALFloatMatrix', '../../machine_exam/handset/test.txt')
print predictX
predictY = producer.build('Classify(GDPredictorLoad(x0, x1), MatrixLinear(x2,x3,x4))').run(producer.merge(gd, p, predictX, 1.0/255.0, 0.0))
predictY.save('output/handset.y')
if __name__ == '__main__':
main()