Last active
March 15, 2021 23:57
-
-
Save hohonuuli/9c73d7abe064a8449468d35eb708d436 to your computer and use it in GitHub Desktop.
Scala VOC parser. For Medium article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.xml.Elem | |
object VocParser { | |
def parse(xml: Elem): Voc = { | |
val filename = (xml \ "filename").text | |
val objects = xml \ "object" | |
val vocObjects = objects.map(n => { | |
val name = (n \ "name").text | |
// VOC is 1-based index. Convert to 0 based. | |
// See https://cv.gluon.ai/_modules/gluoncv/data/pascal_voc/detection.html#VOCDetection | |
val xmin = (n \ "bndbox" \ "xmin").text.toInt - 1 | |
val ymin = (n \ "bndbox" \ "ymin").text.toInt - 1 | |
val xmax = (n \ "bndbox" \ "xmax").text.toInt - 1 | |
val ymax = (n \ "bndbox" \ "ymax").text.toInt - 1 | |
VocObject(name, xmin, ymin, xmax, ymax) | |
}); | |
Voc(filename, objects = vocObjects) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment