Lua 如何保存预训练torch网络中所有批次数据的特征值?
现在我正在使用github的fb torch库 这是我第一次使用torch和lua,所以我遇到了一些问题 我的目标是将特定层的特征向量(resnet的最后一个avg池)与输入图像的类一起保存到一个文件中。所有输入图像均来自cifar-10 db 我想要得到的文件格式如下Lua 如何保存预训练torch网络中所有批次数据的特征值?,lua,deep-learning,torch,resnet,Lua,Deep Learning,Torch,Resnet,现在我正在使用github的fb torch库 这是我第一次使用torch和lua,所以我遇到了一些问题 我的目标是将特定层的特征向量(resnet的最后一个avg池)与输入图像的类一起保存到一个文件中。所有输入图像均来自cifar-10 db 我想要得到的文件格式如下 image1.txt := class index of image and feature vector of image 1 of cifar-10 image2.txt := class index of image an
image1.txt := class index of image and feature vector of image 1 of cifar-10
image2.txt := class index of image and feature vector of image 2 of cifar-10
// and so on through all images of cifar-10
现在我已经看到了该github的一些示例代码
因为这是我第一次使用lua,所以我觉得很难理解这段代码,也很难按照我想要的方式进行修改。我不希望我的数据保存为t7文件格式
model = torch.load(path_to_model):cuda()
avg_pooling_layer = model:get(position_of_the_avg_pooling_layer)
如何访问图层和分类结果索引的值
我不太明白你这是什么意思。如果要查看特定图层的输出或权重。(按照上面的代码)您需要从图层表中获取这些元素。同样,要查看哪些元素是可能的元素,请使用print avg\u pooling\u layer
weights = avg_pooling_layer.weight -- get the weights of the layer
output = avg_pooling_layer.output -- get the output of the layer
如何从cifar-10 db文件(t7批)中读取所有图像
要从t7文件中读取图像,请使用torch功能torch.load
。(以前用于加载模型)
加载后,可以在子表或函数中设置培训和测试集。同样,打印表格并可视化需要获取的值
希望这有帮助
cifar_10 = torch.load("path_to_cifar-10.t7")