Repository: pytorch
Issue: [Caffe2] Check failed: output->size() == values_.size() output size: 1 given size: 1563551
Labels: caffe2

## Question/Support

Hi there, I ran into this error which I've seen in a few places after searching but I am not really sure how to adjust my model to work with caffe2:

```
D/blackbox-ndk: Attempting to load protobuf netdefs...
D/blackbox-ndk: Couldn't parse net from data. Len: 109181755, File: sidewalk_init_net.pb
D/blackbox-ndk: done.
    Instantiating predictor...
A/native: [F given_tensor_fill_op.h:27] Check failed: output->size() == values_.size() output size: 1 given size: 1563551
    terminating.
```

I am using the AICamera code which I've got to work fine using the .pb models but when I add my own it breaks.

It seems related to how I exported the model...

Maybe I am running really old caffe2 cpp code under the NDK (0.8.1 I think)?

## To Reproduce

I exported my code via:
```python
x = Variable(torch.randn(1, 3, 256, 256, requires_grad=True))
x = x.cuda()


torch_out = torch.onnx._export(learn.model, x, f"{DATA_PATH}model.onnx", export_params=True)

import caffe2.python.onnx.backend
import onnx

model = onnx.load(f"{DATA_PATH}model.onnx")

prepared_backend = caffe2.python.onnx.backend.prepare(model)

W = {model.graph.input[0].name: x.data.cpu().numpy()}
# Run the Caffe2 net:
c2_out = prepared_backend.run(W)[0]

np.testing.assert_almost_equal(torch_out.data.cpu().numpy(), c2_out, decimal=3)

from caffe2.python.onnx.backend import Caffe2Backend as c2

init_net, predict_net = c2.onnx_graph_to_caffe2_net(model)
with open(f"{DATA_PATH}sidewalk_init_net.pb", "wb") as f:
    f.write(init_net.SerializeToString())
with open(f"{DATA_PATH}sidewalk_predict_net.pb", "wb") as f:
    f.write(predict_net.SerializeToString())
```


And ran it fine via:

```python
p = workspace.Predictor(init_net, predict_net)
print(img.shape) # (1, 3, 256, 256)
out = p.run([img])
```


The error occurs when I do net->ParseFromArray(data, len):
```c++

loadToNetDef(mgr, &_initNet,   "sidewalk_init_net.pb");

// A function to load the NetDefs from protobufs.
void loadToNetDef(AAssetManager* mgr, caffe2::NetDef* net, const char *filename) {
    AAsset* asset = AAssetManager_open(mgr, filename, AASSET_MODE_BUFFER);
    assert(asset != nullptr);

    const void *data = AAsset_getBuffer(asset);
    assert(data != nullptr);

    off_t len = AAsset_getLength(asset);
    assert(len != 0);

    if (!net->ParseFromArray(data, len)) {
        alog("Couldn't parse net from data. Len: %d, File: %s\n", len, filename);
    }

    AAsset_close(asset);
}

```

## Expected behavior

Load the model successfully without error.

## Environment

 - PyTorch Version (e.g., 1.0): '1.0.0.dev20181125'
 - OS (e.g., Linux): Ubuntu 14.04 LTS
 - How you installed PyTorch (`conda`, `pip`, source): conda nightly
 - Build command you used (if compiling from source):
 - Python version: Python 3.6.6 :: Anaconda, Inc.
 - Any other relevant information: Onnx: '1.3.0'
- caffe2: head -n 20 core/macros.h says: 
```c++
#define CAFFE2_VERSION_MAJOR 0
#define CAFFE2_VERSION_MINOR 8
#define CAFFE2_VERSION_PATCH 1
```

## Other things

- I did come across this: https://github.com/caffe2/caffe2/issues/1076 but I am not sure it helps me since I think I've organized my tensor dimensions by batch_size, color_channels, height, width (1, 3, 256, 256)

- I looked over the the notebook for Squeezenet here: https://github.com/caffe2/AICamera/blob/master/Exporting%20Squeezenet%20to%20mobile.ipynb however nothing appears different during export but obviously, I am using a completely different model.

- Just to ensure I am not doing anything different in the cpp code, I took the same exported models and used them in the AICamera demo instead of the squeeze*.pb files & was able to reproduce the same issue.