我对深度学习很陌生,我正在尝试使用 lua 进行分类。
我已经用 torch 和 lua 5.1 安装了数字,并且我训练了以下模型:
我已经导出了模型,现在我正在尝试使用以下 lua 代码进行分类:
local image_url = '/home/delpech/mnist/test/5/04131.png'
local network_url = '/home/delpech/models/snapshot_30_Model.t7'
local network_name = paths.basename(network_url)
print '==> Loading network'
local net = torch.load(network_name)
--local net = torch.load(network_name):unpack():float()
net:evaluate()
print(net)
print '==> Loading synsets'
print 'Loads mapping from net outputs to human readable labels'
local synset_words = {}
--for line in io.lines'/home/delpech/models/labels.txt' do table.insert(synset_words, line:sub(11)) end
for line in io.lines'/home/delpech/models/labels.txt' do table.insert(synset_words, line) end
print 'synset words'
for line in io.lines'/home/delpech/models/labels.txt' do print(line) end
print '==> Loading image and imagenet mean'
local im = image.load(image_url)
print '==> Preprocessing'
local I = image.scale(im,28,28,'bilinear'):float()
print 'Propagate through the network, sort outputs in decreasing order and show 10 best classes'
local _,classes = net:forward(I):view(-1):sort(true)
for i=1,10 do
print('predicted class '..tostring(i)..': ', synset_words[classes[i]])
end
但这里是输出:
delpech@delpech-K55VD:~/models$ lua classify.lua
==> Downloading image and network
==> Loading network
nn.Sequential {
[input -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> output]
(1): nn.MulConstant
(2): nn.SpatialConvolution(1 -> 20, 5x5)
(3): nn.SpatialMaxPooling(2x2, 2,2)
(4): nn.SpatialConvolution(20 -> 50, 5x5)
(5): nn.SpatialMaxPooling(2x2, 2,2)
(6): nn.View(-1)
(7): nn.Linear(800 -> 500)
(8): nn.ReLU
(9): nn.Linear(500 -> 10)
(10): nn.LogSoftMax
}
==> Loading synsets
Loads mapping from net outputs to human readable labels
synset words
0
1
2
3
4
5
6
7
8
9
==> Loading image and imagenet mean
==> Preprocessing
Propagate through the network, sort outputs in decreasing order and show 5 best classes
predicted class 1: 4
predicted class 2: 8
predicted class 3: 0
predicted class 4: 1
predicted class 5: 9
predicted class 6: 6
predicted class 7: 7
predicted class 8: 2
predicted class 9: 5
predicted class 10: 3
而这其实并不是数字提供的分类……