Repository: pytorch
Issue: (CAFFE_ENFORCE_EQ_WITH_CALLER tensor.h) caffe2 C++ windows10  runtime error! 
Labels: caffe2

## Issue description

I have successfully build and install caffe2 on windows 10 and while i am testing my below code in visual studio 2017, i got an run-time error when Creating a tensor (TensorCPU), and filling its contents with the given values from my script.
I have compiled and test this code on ubuntu and it is function in a good way..

## Code example
`
`#include <tuple>
#include <caffe2/core/init.h>
#include <caffe2/core/net.h>
#include <caffe2/utils/proto_utils.h>
#include <iostream>
#include <cstdio>
#include <ctime>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "classes.h"
CAFFE2_DEFINE_string(init_net, "C:\\Users\\HIMA\\source\\repos\\ConsoleApplication1\\model\\init_net.pb", "init net");
CAFFE2_DEFINE_string(predict_net, "C:\\Users\\HIMA\\source\\repos\\ConsoleApplication1\\model\\predict_net.pb", "predict net");
CAFFE2_DEFINE_string(file, "C:\\Users\\HIMA\\source\\repos\\ConsoleApplication1\\image\\lemon.jpg", "list of images separated by comma");
CAFFE2_DEFINE_int(size, 224, "image size in pixel");
namespace caffe2 {
	cv::Mat preprocess(const std::string& image_file, int* min_size, int* max_size, bool use_crop, float& scale) {
		cv::Mat image = cv::imread(image_file);
		cv::Size dst_size;
		if (min_size != nullptr) {
			dst_size.width = std::max(*min_size * image.cols / image.rows, *min_size);
			dst_size.height = std::max(*min_size * image.rows / image.cols, *min_size);
		}
		else if (max_size != nullptr) {
			if (image.cols > *max_size && image.rows > *max_size) {
				dst_size.width = std::min(*max_size * image.cols / image.rows, *max_size);
				dst_size.height = std::min(*max_size * image.rows / image.cols, *max_size);
			}
			else {
				dst_size.width = image.cols;
				dst_size.height = image.rows;
			}
		}
		else {
			CAFFE_ENFORCE(false);
		}
		scale = static_cast<float>(image.cols) / dst_size.width;

		cv::resize(image, image, dst_size);
		if (use_crop) {
			int size = std::min(image.cols, image.rows);
			cv::Rect crop((image.cols - size) / 2, (image.rows - size) / 2, size, size);
			image = image(crop);
		}
		image.convertTo(image, CV_32FC3, 1.0, -128);
		return image;
	}


	void run() {
		std::cout << std::endl << "==> using CPU" << std::endl;
		DeviceOption device_option;
		std::shared_ptr<CPUContext> ctx_cpu;
		device_option.set_device_type(CPU);
		ctx_cpu.reset(new CPUContext(device_option));
		std::cout << std::endl << "==> using CPU" << std::endl;


		std::cout << "==> init network" << std::endl;
		NetDef init_net, predict_net;
		CAFFE_ENFORCE(ReadProtoFromFile(FLAGS_init_net, &init_net));
		CAFFE_ENFORCE(ReadProtoFromFile(FLAGS_predict_net, &predict_net));
		Workspace workspace("default");
		CAFFE_ENFORCE(workspace.RunNetOnce(init_net));


		// https://stackoverflow.com/questions/1894886/parsing-a-comma-delimited-stdstring/10861816
		std::cout << "==> parse image list" << std::endl;
		std::stringstream ss(FLAGS_file);
		std::vector<std::string> image_list;
		while (ss.good()) {
			std::string substr;
			std::getline(ss, substr, ',');
			image_list.push_back(substr);
		}
		size_t batch_size = image_list.size();
		CAFFE_ENFORCE(true);

		std::cout << "==> prepare batch ";
		const size_t channel(3);
		std::vector<float> data_batch;
		std::vector<float> info_batch;
		for (const std::string& image_file : image_list) {
			// load image
			bool use_crop = true;
			float scale;
			cv::Mat image;
			image = preprocess(image_file, &FLAGS_size, nullptr, /* use_crop */  true, scale);
			info_batch.push_back(image.rows);
			info_batch.push_back(image.cols);
			info_batch.push_back(scale);

			// convert NHWC to NCHW
			std::vector<cv::Mat> channels(channel);
			cv::split(image, channels);
			std::vector<float> data;
			for (cv::Mat &c : channels) {
				data.insert(data.end(), (float *)c.datastart, (float *)c.dataend);
			}
			data_batch.insert(data_batch.end(), data.begin(), data.end());
		}

		std::clock_t start;
		double duration;
		start = std::clock();

		size_t height = info_batch[0];
		size_t width = info_batch[1];
		std::cout << "(" << batch_size << " x " << channel << " x " << height << " x " << width << ")" << std::endl;
		std::vector<TIndex> dims(( batch_size, channel, height, width ));
		**_TensorCPU tensor(dims, data_batch, nullptr);  // here is the function that call tensor.h_**
		TensorCPU im_info(std::vector<TIndex>(batch_size, 3), info_batch, nullptr);


		std::cout << "==> feedforward" << std::endl;

		workspace.CreateBlob("0")->GetMutable<TensorCPU>()->CopyFrom(tensor);

		CAFFE_ENFORCE(workspace.RunNetOnce(predict_net));


		auto&output = workspace.GetBlob("442")->Get<TensorCPU>();

		std::cout << "==> retrieve results" << std::endl;
		for (size_t i = 0; i < batch_size; i++) {
			const auto&prob = output.data<float>() + i * classes.size();
			std::vector<float> pred(prob, prob + classes.size());
			auto it = std::max_element(std::begin(pred), std::end(pred));
			auto maxValue = *it;
			auto maxIndex = std::distance(std::begin(pred), it);
			std::string image_file = image_list[i].substr(image_list[i].find_last_of('/') + 1);
			std::cout << "P( " << classes[maxIndex] << " | " << image_file
				<< " ) = " << maxValue << std::endl;
		}
		duration = (std::clock() - start) / (double)CLOCKS_PER_SEC;
		std::cout << "printf: " << duration << '\n';
	}

}
int main(int argc, char **argv) {
	caffe2::GlobalInit(&argc, &argv);
	caffe2::run();
	return 0;
}
`
`

The error happen in this line below on tensor.h
`CAFFE_ENFORCE_EQ_WITH_CALLER(values.size(), size_);`


## System Info
Unhandled exception at 0x00007FFED188F218 in ConsoleApplication1.exe: Microsoft C++ exception: caffe2::EnforceNotMet at memory location 0x000000C439AFE870.


- Caffe2
- install from Source
- Build as release from visual studio 
- OS: Windows 10