forked from iitkliv/Surgical-workflow-modelling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
featureExtraction.lua
42 lines (33 loc) · 1020 Bytes
/
featureExtraction.lua
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
require 'nn'
require 'cudnn'
require 'cunn'
require 'rnn'
matio = require 'matio'
net = torch.load('Net_cnn')
model= net:get(1)
-- for googlenet
model:remove(25)
model:remove(24)
--extract features
print('Loading data')
TestData = torch.div(matio.load('data/trainData.mat','trainData'):float(),255)
print('data loaded!')
local Net_pred = torch.Tensor(TestData:size(1),2048)
batchSize = 32
local SizeData = TestData:size(1)
SizeBatch = math.floor(TestData:size(1)/batchSize)
local yt,x;
local num = 1;
for NumBatches=1,SizeBatch do
print(NumBatches .. '/' .. SizeBatch)
x = TestData[{{num,num+batchSize-1},{},{},{}}]:cuda()
y = model:forward(x)
Net_pred[{{num,num+batchSize-1},{}}] = y:float()
num = num + batchSize
end
if(TestData:size(1)%batchSize ~= 0) then
x = TestData[{{num,TestData:size(1)},{},{},{}}]:cuda()
y = model:forward(x)
Net_pred[{{num,TestData:size(1)},{}}] = y:float()
end
matio.save('Net_cnn_feat.mat',Net_pred);