fix the deeptext issue (#14005)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14005

the partial initialization of tensor is no longer supported, we need to fix multiple places

Reviewed By: hl475

Differential Revision: D13078206

fbshipit-source-id: a1be2bd2a9f573db54e1366a0d7a17cc2e0db0c9
This commit is contained in:
Lingyi Liu
2018-11-15 12:11:35 -08:00
committed by Facebook Github Bot
parent b8de8f6261
commit 5639332a28
2 changed files with 8 additions and 2 deletions

View File

@ -212,7 +212,13 @@ void fillInputBlob(
caffe2::TensorProto* tensor_proto =
tensor_kv.second.mutable_protos(iteration % protos_size);
if (tensor_proto->data_type() == caffe2::TensorProto::STRING) {
caffe2::TensorCPU* tensor = BlobGetMutableTensor(blob, caffe2::CPU);
vector<int64_t> dims;
for (const int64_t d : tensor_proto->dims()) {
dims.push_back(d);
}
caffe2::TensorCPU* tensor = BlobGetMutableTensor(
blob, dims, at::dtype<string>().device(caffe2::CPU));
int total_size = tensor_proto->string_data_size();
for (size_t i = 0; i < total_size; i++) {
(tensor->mutable_data<string>())[i] = tensor_proto->string_data(i);

View File

@ -36,7 +36,7 @@ int main(int argc, char** argv) {
while (std::getline(f_in, line)) {
caffe2::TensorProto* data = tensor_protos.add_protos();
data->set_data_type(caffe2::TensorProto::STRING);
data->add_dims(0);
data->add_dims(1);
data->add_string_data(line);
data->set_name("text");
}