a
    ==ic                     @   s6  d dl Z d dlmZ d dlZd dlmZ d dlmZ d dl	m
  m  mZ ejddddgid	ejd
eddejdeddejdedddejdeddejdddeddddd Zejddddgid	ejdeddejdddedddejddedd dd!d" ZdS )#    N)
caffe2_pb2)
ModelProto)Caffe2Backendz convert caffe2 net to onnx modelhelp_option_namesz-hz--help)helpcontext_settings
caffe2_netrb)typez--caffe2-net-namezName of the caffe2 net)r
   r   z--caffe2-init-netz#Path of the caffe2 init net pb filez--value-infozDA json string providing the type and shape information of the inputsz-oz--outputTwbz&Output path for the onnx model pb file)requiredr
   r   c                 C   s   t  }||   |js*|s*td|p2|j|_|r^t  }||  d||_nd }|rpt	|}t
j|||d}||  d S )NzKThe input caffe2 net does not have name, --caffe2-net-name must be providedz{}_init)predict_netinit_net
value_info)r   ZNetDefParseFromStringreadnameclickBadParameterformatjsonloadsc2_onnxZcaffe2_net_to_onnx_modelwriteSerializeToString)r   Zcaffe2_net_nameZcaffe2_init_netr   outputZc2_net_protoZc2_init_net_proto
onnx_model r   r/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/caffe2/python/onnx/bin/conversion.pycaffe2_to_onnx   s(    

r   z convert onnx model to caffe2 netr   z#Output path for the caffe2 net filez--init-net-outputz(Output path for the caffe2 init net filec                 C   sB   t  }||   t|\}}||  ||  d S )N)r   r   r   c2Zonnx_graph_to_caffe2_netr   r   )r   r   Zinit_net_outputZonnx_model_protor   r   r   r   r   onnx_to_caffe2D   s
    r!   )r   Zcaffe2.protor   r   Zonnxr   Zcaffe2.python.onnx.backendr   r    Zcaffe2.python.onnx.frontendpythonZfrontendr   commandargumentFileoptionstrr   r!   r   r   r   r   <module>   sX   

