Skip to content

torch::Tensor can't be use with std::tuple or std::vector? #759

Open
@williamlzw

Description

@williamlzw

#include <torch/torch.h>
#include <Windows.h>
#include
#include
#include

auto ReadRsv(const std::string path) {
HANDLE filea= CreateFileA((LPCSTR)path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,NULL);
int cout;
int length;
ReadFile(filea, &cout,4,NULL,NULL);
std::vector<std::tuple<torch::Tensor, torch::Tensor>> rsv;
byte* dataa = new byte[784];
byte* datab = new byte[1];
DWORD hasread;
for (int i = 0; i<cout; ++i) {
ReadFile(filea, &length, 4, &hasread, NULL);
ReadFile(filea, &dataa, 784, &hasread, NULL);
torch::Tensor line = torch::from_blob(&dataa, { 784 },torch::kByte);
ReadFile(filea, &datab, 1, &hasread, NULL);
torch::Tensor label = torch::from_blob(&datab, { 1 }, torch::kByte);
rsv.push_back(std::make_tuple(line,label)); //wrong?
}
delete []dataa;
delete []datab;
CloseHandle(filea);
return rsv;
}


win10 x64;libtorch 1.5 release x64;

download rsv file: https://share.weiyun.com/5DYsiDe

when i=0,it run success,but when i=1,it run wrong.
0x00007FFD618EF7E4 (torch_cpu.dll) (in consoleapplication1.exe) throws an exception: 0xC0000005: an access conflict occurs while writing to location 0x0000000000000000.
Remove this sentence and it will run successfully ->rsv.push_back(std::make_tuple(line,label));

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions