Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 如何保存预训练torch网络中所有批次数据的特征值?_Lua_Deep Learning_Torch_Resnet - Fatal编程技术网

Lua 如何保存预训练torch网络中所有批次数据的特征值?

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

现在我正在使用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 and feature vector of image 2 of cifar-10
 // and so on  through all images of cifar-10
现在我已经看到了该github的一些示例代码

因为这是我第一次使用lua,所以我觉得很难理解这段代码,也很难按照我想要的方式进行修改。我不希望我的数据保存为t7文件格式

  • 如何通过lua从torch的网络中仅访问一个特定层?(上次平均池)
  • 如何访问图层和分类结果索引的值
  • 如何从cifar-10 db文件(t7批)中读取所有图像
  • 对不起,问题太多了。但我觉得很难使用火炬,因为社区线程和火炬张贴池amouns。。请理解我

    如何通过lua从torch的网络中仅访问一个特定层?(上次平均池)

    要访问每个层,您只需加载模型并使用整数获取它。如果您打印模型,您将能够看到上次平均池的位置

    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")