Setting up calibration batch data for INT8

I am trying to perform INT8 calibration for a Caffe model. It is a fully convolutional net with PReLU activations, which have been supported through the TensorRT plugin layer API. The build is pretty much identical to the sample code provided by TensorRT.

I am currently getting this error:

Calibration failure occured with no scaling factors detected. Please see int8 sample to setup calibration correctly.

My batch files are being set up according to the following function:
def write_next_batch(self):
if self.batch < self.max_batches:
imgs =
for f in self.files: //loop over files
# print("[ImageBatchStream] Processing “, f)
img = ImageBatchStream.read_image_chw(f)
img = self.preprocessor(img)
imgs.append(img)
for i in range(len(imgs)):
# pdb.set_trace()
self.calibration_data[i] = imgs[i]
# self.batch += 1
# pdb.set_trace()
print(len(self.files),CHANNEL, HEIGHT,WIDTH)
output_file = open(”/home/dave/TensorRT-4.0.0.3/data/mnist/batch/batch"+str(self.batch), ‘a’)
contiguousarray = np.ascontiguousarray([len(self.files), CHANNEL, HEIGHT, WIDTH], dtype=np.int32)
output_file.write(contiguousarray)
contiguousarray = np.ascontiguousarray(self.calibration_data, dtype=np.float32)
output_file.write(contiguousarray)
contiguousarray = np.ascontiguousarray(np.ones((1,len(self.files))), dtype=np.float32)
output_file.write(contiguousarray)
output_file.close()
else:
exit()

By calling
a = np.fromfile(path_to_batch, dtype=np.float32)
I can compare my batches to those provided in the samples and their formats looks identical. Does anyone have any suggestion for how this issue can be resolved?