pythonpytorchcaffe2

Enabling CAFFE2 while building pytorch from source on Windows command prompt


So, I was doing a model train up using Yolo7 on Windows platform and

C:\Users\LENOVO>python train.py --weights yolov7.pt --data "data/custom.yaml" --workers 4 --batch-size 4 --img 416 --cfg cfg/training/yolov7.yaml --name yolov7 --hyp data/hyp.scratch.p5.yaml

After running the above command the below stack trace of error showed up in my command prompt on windows. My question is:

  1. How to do the suggestions of the error below? How to enable the BUILD_CAFFE2=1 while building pytorch on my Windows? Not using Conda of course. On my Windows command prompt only.
  2. I installed pytorch from using the following source https://github.com/pytorch/pytorch#from-source Install caffe2 using commands from this source https://caffe2.ai/docs/getting-started.html?platform=windows&configuration=compile But the following error still shows while training my model.

I just need to know the command of enabling build_caffe2=1 on windows command prompt.

    C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\caffe2\__init__.py:5: UserWarning: Caffe2 support is not fully enabled in this PyTorch build. Please enable Caffe2 by building PyTorch from source with `BUILD_CAFFE2=1` flag.
     warnings.warn("Caffe2 support is not fully enabled in this PyTorch build. "
    C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\caffe2\proto\__init__.py:17: UserWarning: Caffe2 support is not enabled in this PyTorch build. Please enable Caffe2 by building PyTorch from source with `BUILD_CAFFE2=1` flag.
     warnings.warn('Caffe2 support is not enabled in this PyTorch build. '
    C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\caffe2\python\__init__.py:9: UserWarning: Caffe2 support is not enabled in this PyTorch build. Please enable Caffe2 by building PyTorch from source with `BUILD_CAFFE2=1` flag.
     warnings.warn('Caffe2 support is not enabled in this PyTorch build. '
    Traceback (most recent call last):
     File "C:\Users\LENOVO\train.py", line 8, in <module>
    from caffe2.python import core, scope
      File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\caffe2\python\__init__.py", line 7, in <module>
    from caffe2.proto import caffe2_pb2
      File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\caffe2\proto\__init__.py", line 15, in <module>
    from caffe2.proto import caffe2_pb2, metanet_pb2, torch_pb2
    ImportError: cannot import name 'metanet_pb2' from partially initialized module 'caffe2.proto' (most likely due to a circular import) (C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\caffe2\proto\__init__.py)

   
 

Solution

  • I have solved the issue but setting BUILD_CAFFE2=1 on the command prompt before installing pytorch, with the following code.

    set BUILD_CAFFE2=1