Repository: pytorch
Issue: [Caffe2] Error when loading a leveldb dataset using brew.db_input (Error protos.protos_size() == OutputSize().)
Labels: caffe2

Hi all,

I am trying to **load a leveldb dataset using brew.db_input** with the Python API. I used the following relevant code:

```
def add_input(self, model, batch_size, db, db_type, device_opts):
        with core.DeviceScope(device_opts):
            # load the data
            data, label = brew.db_input(
                model,
                blobs_out=["data", "label"],
                batch_size=batch_size,
                db=db,
                db_type=db_type,
            )

            # don't need the gradient for the backward pass
            data = model.StopGradient(data, data)

            return data, label
.
.
.

# == Training model ==
    	train_model= model_helper.ModelHelper(name="train_net", arg_scope=arg_scope)
    	data, label = self.add_input(train_model, batch_size=batch_size, db=os.path.join(self._data_dir_, 'TORCS_Training_1F'), db_type='leveldb', device_opts=device_opts)
    	predictions = self.create_model(train_model, data, label, device_opts=device_opts)
    	self.add_training_operators(train_model, predictions, label, device_opts, opt_type, base_learning_rate, policy, stepsize, epsilon, beta1, beta2, gamma, momentum)
    	self.add_accuracy(train_model, predictions, label, device_opts, eval_metric)
    	with core.DeviceScope(device_opts):
    		brew.add_weight_decay(train_model, weight_decay)

    	# Initialize and create the training network
    	workspace.RunNetOnce(train_model.param_init_net)
    	workspace.CreateNet(train_model.net, overwrite=True)

    	# Main Training Loop
    	print("== Starting Training for " + str(num_epoch) + " epochs ==")
    	for i in range(num_epoch):
    		workspace.RunNet(train_model.net)
    		if i % 50 == 0:
    			print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy'))
    	print("Training done")
```

However, I got the following error:
```
WARNING: Logging before InitGoogleLogging() is written to STDERR
E1124 13:53:47.919953  8191 prefetch_op.h:110] Prefetching error [enforce fail at tensor_protos_db_input.h:68] protos.protos_size() == OutputSize().  
E1124 13:53:47.920176  8161 prefetch_op.h:83] Prefetching failed.
E1124 13:53:47.936815  8161 net_simple.cc:63] Operator failed: input: "dbreader_./data/dpnet_dpnet/TORCS_Training_1F" output: "data_uint8" output: "label" name: "" type: "TensorProtosDBInput" arg { name: "batch_size" i: 64 } device_option { device_type: 1 cuda_gpu_id: 0 }
WARNING:caffe2.python.workspace:Original python traceback for operator `-1107198840` in network `train_net` in exception above (most recent call last):
Traceback (most recent call last):
  File "CNNTrainer_dpnet_dpnet.py", line 23, in <module>
    stepsize=8000
  File "/home/carlos/Documents/git/Caffe2_scripts/caffe2_torcs_predictor/CNNCreator_dpnet_dpnet.py", line 158, in train
    workspace.RunNet(train_model.net)
  File "/home/carlos/Documents/git/pytorch/build/caffe2/python/workspace.py", line 217, in RunNet
    StringifyNetName(name), num_iter, allow_fail,
  File "/home/carlos/Documents/git/pytorch/build/caffe2/python/workspace.py", line 178, in CallWithExceptionIntercept
    return func(*args, **kwargs)
RuntimeError: [enforce fail at pybind_state.cc:1025] success. Error running net train_net 
```

The leveldb dataset employed is the one used by DeepDriving (http://deepdriving.cs.princeton.edu/)  along with caffe (previous framework of Caffe2). Therefore, I know that the dataset is fine and could be loaded with caffe. **Am I doing something wrong here?
`data, label = self.add_input(train_model, batch_size=batch_size, db=os.path.join(self._data_dir_, 'TORCS_Training_1F'), db_type='leveldb', device_opts=device_opts)`
Is there a difference when loading leveldb datasets between Caffe and Caffe2?**