{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"**If you think it's useful, please give me an upvote, thanks.**"},{"metadata":{},"cell_type":"markdown","source":"## 1 - \n**Because predicting the local orientation (𝜃𝑙) is better than predicting global (𝜃) directly******\n\n**We let the 𝜃 = 𝜃𝑙 +  𝜃**ray"},{"metadata":{},"cell_type":"markdown","source":"![1](https://img-blog.csdnimg.cn/20190608110711257.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI5NDYyODQ5,size_16,color_FFFFFF,t_70)"},{"metadata":{},"cell_type":"markdown","source":"# 2 - \n**Apparently it's easier to learn the orientation as a classification problem (eg. is the object facing forward/backward) then finetune the angle within the classified orientation than it is to just regress the angle.**\n\n**Centernet splits the orientation angle in two overlapping 240º bins centered at -90º and 90º. **\n\n**For each bin, two scalars + softmax are used to predict if the angle falls into the bin, then two more scalars are used to encode the angle as sin(angle) and cos(angle).**\n\n**thanks for your explanation @ Prof.Bacterio**"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","collapsed":true,"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":false},"cell_type":"code","source":"import numpy as np\n# get 𝜃𝑙 (Counter clockwise is positive)\ndef get_alpha(rot):\n  # output: (Batch, 8) [bin1_cls[0], bin1_cls[1], bin1_sin, bin1_cos, \n  #                     bin2_cls[0], bin2_cls[1], bin2_sin, bin2_cos]\n  # return rot[:, 0]\n    idx = rot[:, 1] > rot[:, 5]\n    \n    # alpha1 is relative to -90º\n    alpha1 = np.arctan(rot[:, 2] / rot[:, 3]) + (-0.5 * np.pi)\n    \n    # alpha2 is relative to +90º\n    alpha2 = np.arctan(rot[:, 6] / rot[:, 7]) + ( 0.5 * np.pi)\n    \n    return alpha1 * idx + alpha2 * (1 - idx)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# you need to do some finetune to get real 𝜃ray\n# np.arctan2(x, z)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}