facebookresearch / detectron2

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
https://detectron2.readthedocs.io/en/latest/
Apache License 2.0
30.4k stars 7.47k forks source link

Exception: Cannot find operator schema for Cast. Will skip schema checking. #1051

Closed Quincy567 closed 4 years ago

Quincy567 commented 4 years ago

Hello, First,I have exported “COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml” model(trained in my dataset) to caffe2 model using "caffe2_converter.py". Second, I used caffe2 api in libtorch(CPU edition in pytorch.org, 1.4 and 1.5-preview all have tried) to deploy model, an exception occured "Cannot find operator schema for Cast. Will skip schema checking",and it shutdown, how can I solve it???

Environment: model is trained and exported to caffe2 in Ubuntu Server 18.04 , deployed in Win10 X64, VisualStudio2019(using Visual Studio 2017 (v141) toolchain, x64, libtorch 1.4 or 1.5 preview all tried, pytorch1.4 or 1.5 preview all tried ). Detectron2 edition:latest. Codes:

void main(int argc, char** argv)
{
    string initNetPath = "C:/Users/h/Desktop/Processed/caffe2_model/model_init.pb";
    string predictNetPath = "C:/Users/h/Desktop/Processed/caffe2_model/model.pb";

    const int predHeight = 1944;
    const int predWidth = 2592;
    const int batch = 1;     
    const int channels = 3;

    caffe2::NetDef initNet_, predictNet_;
    CAFFE_ENFORCE(ReadProtoFromFile(initNetPath, &initNet_));
    // >>> with open(path_to_PREDICT_NET) as f:
    CAFFE_ENFORCE(ReadProtoFromFile(predictNetPath, &predictNet_));

    for (int i = 0; i < predictNet_.op_size(); ++i) {
        predictNet_.mutable_op(i)->mutable_device_option()->set_device_type(0);
        printf((to_string(i) + " " + predictNet_.mutable_op(i)->type() + "\r\n").c_str());
    }
    for (int i = 0; i < initNet_.op_size(); ++i) {
        initNet_.mutable_op(i)->mutable_device_option()->set_device_type(0);
        printf((to_string(i) + " " + initNet_.mutable_op(i)->type() + "\r\n").c_str());

    }

    Workspace workSpace;
    CAFFE_ENFORCE(workSpace.CreateNet(predictNet_));    //exception occured 
    CAFFE_ENFORCE(workSpace.RunNetOnce(initNet_));
    std::vector<int> dims({ batch * channels * predHeight * predWidth });
    TensorCPU input = TensorCPU(dims, CPU);
    vector<float> imgArray(batch * channels * predHeight * predWidth);
    input.ShareExternalPointer(imgArray.data());
    auto data = workSpace.GetBlob("data")->GetMutable<TensorCPU>();
    data->CopyFrom(input);
    workSpace.RunNet(predictNet_.name());
}
ppwwyyxx commented 4 years ago

According to https://github.com/pytorch/pytorch/issues/14940#issuecomment-450303336 it seems that on windows, the official pytorch package does not include caffe2 components.

Quincy567 commented 4 years ago

Thanks! I will build caffe2 myself on windows and try again.

sidsathi commented 4 years ago

@Quincy567 Did you have any luck with getting the Caffe2 model to work on windows?

ppwwyyxx commented 4 years ago

We can't provide much help on windows. But now there is a C++ inference example that works on Linux. https://detectron2.readthedocs.io/tutorials/deployment.html#use-the-model-in-c-python