-
Notifications
You must be signed in to change notification settings - Fork 7
/
DeepSEA.lua
128 lines (92 loc) · 2.71 KB
/
DeepSEA.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
----------------------------------------------------------------------
-- This script makes predictions using a DeepSEA model
-- for a minimal example run 'luajit DeepSEA.lua --dataset example_1k'
----------------------------------------------------------------------
require 'paths'
require 'nn'
require 'math'
require 'torch'
require 'string'
require 'sys'
----------------------------------------------------------------------
print 'Processing options'
cmd = torch.CmdLine()
cmd:text()
cmd:text('ENCODE Loss Function')
cmd:text()
cmd:text('Options:')
cmd:option('-seed', 1, 'fixed input seed for repeatable experiments')
cmd:option('-threads', 1, 'number of threads')
cmd:option('-type', 'float', 'type: double | float | cuda')
cmd:option('-netPath','','overide which model to use for prediction')
cmd:option('-test_file_h5','','test file in h5 format')
cmd:option('-setDevice', 1, 'specify which gpu to use. only effective when type is cuda.')
cmd:option('-dataset','','dataset')
cmd:text()
opt = cmd:parse(arg or {})
DATASET = opt.dataset
-- nb of threads and fixed seed (for repeatable experiments)
if opt.type == 'float' then
print('Switch to float')
torch.setdefaulttensortype('torch.FloatTensor')
elseif opt.type == 'cuda' then
print('Switch to CUDA')
require 'cutorch'
require 'cunn'
torch.setdefaulttensortype('torch.FloatTensor')
cutorch.setDevice(opt.setDevice)
end
torch.setnumthreads(opt.threads)
torch.manualSeed(opt.seed)
batchSize = 1000
--Read Input Data File
npy4th = require 'npy4th'
loaded = npy4th.loadnpy("./"..DATASET..".npy")
testData = {
data = loaded
}
--Read DeepSEA model
if opt.netPath~='' then
filename = opt.netPath
else
filename = './deepsea.cpu'
end
model = torch.load(filename)
if opt.type == 'cuda' then
model:cuda()
else
model:float()
end
model:evaluate() -- turn off dropout for production mode
nfeats = 4
width = 1000
noutputs = 919
height = 1
predSize = testData.data:size(1)
torch.setdefaulttensortype('torch.FloatTensor')
--Make predictions with DeepSEA model
alloutputs = torch.DoubleTensor(predSize, noutputs)
for t = 1,predSize,batchSize do
--print(t)
collectgarbage()
local inputs = torch.FloatTensor(math.min(batchSize, predSize-t+1), nfeats, width, height)
-- create mini batch
k = 1
for i = t,math.min(t+batchSize-1,predSize) do
-- load new sample
input = testData.data[i]:float()
inputs[k]= input
k = k + 1
end
if opt.type == 'cuda' then
inputs = inputs:cuda()
end
local output = model:forward(inputs):double()
k=1
for ii = t,math.min(t+batchSize-1,predSize) do
alloutputs[ii] = output[k]
k=k+1
end
end
--Save predictions
npy4th.savenpy("./"..DATASET.."_deepsea.npy",alloutputs)