machine-learning - 以张量作为输入的 MLP 构造

标签 machine-learning lua neural-network computer-vision torch

我正在创建一个简单的神经网络,其中有一个隐藏层用于分类。 我的输入数据集已准备好并保存在 .t7 文件中。

input =
{
  data : DoubleTensor - size: 1400x1002x3
  label : DoubleTensor - size: 1400
}

这是我创建的 My MLP 的代码

------------------------Neural Netwrok-------------------------

net = nn.Sequential()
inputs= "?" ; outputs=70; HUs= 25 --parameters & the problem is in my input "?" 
--that i am asking for.what shall i write there ? at the time i have the input 
--described above. 
        net:add( nn.Linear(inputs, HUs) ) 
        net:add(nn.ReLU()) -- Activation function
        net:add( nn.Linear(HUs, outputs) ) -- 70 output : classes of mpeg7

----------------------------------------------------------------------
print('NN : ' .. net:__tostring())
-------------------------Loss Function-------------------------
criterion=nn.ClassNLLCriterion() --Negative Log-Likelihood (NLL) Criterion
print('Duree NN : ' .. os.time())


---------------------- Loading Data ---------------------------------
trainset=torch.load('TrainSetTable.t7')

------------------------TRAINING MY NETWORK----------------------

trainer=nn.StochasticGradient(net,criterion)
trainer.learningRate = 0.0005
trainer.maxIteration = 10

print('------------------------------------------------------------------------')
print('training epoch : ' .. trainer.maxIteration .. ', learning rate : ' .. trainer.learningRate .. ' , learning rate decay : ' .. trainer.learningRateDecay)
print('------------------------------------------------------------------------')

trainer:train(trainset)
print('Duree Training : ' .. os.time())

net=net:double()
net:clearState()
torch.save('TrainedNN/NN_Mpeg7_10Epoch.t7',net)
print('Duree sauvegarde : ' .. os.time())

我怎么能说我的神经网络的输入是一个张量?

input.data(全部)是一个大小为1400x1002x3的张量,包含我的形状:我正在处理包含1400个形状的mpeg7数据集,每个形状对我来说都是1002*3矩阵。 input.label 是一个大小为 1400 的张量,包含每个形状的相应标签。

我是 torch 和 lua 的新手..但是在我看到的示例中,就像上面的代码一样,数据在构建后被导入并馈送到神经网络。那么在加载数据之前我应该​​写什么作为神经网络的输入?如何让它“理解”稍后将向其提供如下数据:

trainset=torch.load('TrainSetTable.t7')
trainset.data=trainset.data:view(980,1,1002,3)

{One_train_contour = DoubleTensor - 1x1002x3 }

总共

{
 data(train_contours) : DoubleTensor - 980x1002x3
 label : DoubleTensor - size: 1400
}

我有

{
 data(test_contours) : DoubleTensor - 420x1002x3
 label : DoubleTensor - size: 1400
}

我建议在该行中写什么 输入=“?”

最佳答案

重要的是,在输入任何数据之前定义神经网络输入层。 请注意,神经网络的输入与样本数量(在分类网络中)无关,并且仅取决于每个数据样本的配置。

我对mpeg不熟悉,但是如果mpeg的每个样本的尺寸为32x32 那么您的输入应该是 1024(与 MNIST 数据集的情况一样)

来源:http://yann.lecun.com/exdb/mnist/

关于machine-learning - 以张量作为输入的 MLP 构造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57183226/

相关文章:

python - 如何使用pickle进行序列化

python - GridSearchCV 是否存储所有参数组合的所有分数?

c++ - 在 C++ 中使用嵌入式 lua 从外部目录加载文件?

c++ - 从 lua 5.2 调用 c 函数会产生语法错误

python - 如何在多个目标变量上训练我的 pylearn2 神经网络?

c++ - 从caffe中提取特征

tensorflow - 如何解决,没有名为 'tf' 的模块?

python - Pytorch 预期为 1D 张量,但得到了 2D 张量

redis - 如何将一些键值对传递给redis zadd?

python - Tensorflow:分类概率分布的 KL 散度