The accurate and precise contour extraction on SEM image is important to measure overlay, improve OPC model, inspect tiny hot-spot, and so on. In 2019, we reported about the measurement repeatability of edge placement error (EPE) with Die-to-Database (D2DB) algorithm. In this study, we apply machine learning for the contour extraction to improve the measurement throughput with high accuracy and precision of EPE on 2D pattern. The pattern contour on SEM image can be extracted by processing gray-level profile data across the measurement line. Generally, in order to extract the precise contour, the direction of the profile should be perpendicular to the pattern contour. Although the direction used to be determined by the design pattern, it can’t be accurate enough to extract the contour exactly since the shape between the design pattern and the actual pattern are different. We propose the method that determines the direction of the profile acquisition using the contour taken by machine learning, which is more similar to the actual pattern contour than the design pattern contour. The accuracy and the precision of EPE measurement using the contour extracted by our method has been improved in actual SEM images captured repeatedly.