Class YoloAnnotationsReportWriter

  • All Implemented Interfaces:
    CleanUpHandler, Destroyable, GlobalInfoSupporter, FileFormatHandler, LoggingLevelHandler, LoggingSupporter, OptionHandler, ShallowCopySupporter<AbstractReportWriter>, SizeOfHandler, ReportWriter<Report>, StringReportWriter<Report>, Serializable, Comparable

    public class YoloAnnotationsReportWriter
    extends AbstractReportWriter<Report>
    implements StringReportWriter<Report>
    Writes text files with YOLO object annotations, one object definition per line:
    BBox format:
    - format: <object-class> <x> <y> <width> <height>
    - object-class: 0-based index
    - x/y: normalized center of annotation
    - width/height: normalized width/height
    - Normalization uses image width/height
    Polygon format:
    - format: <object-class> <x0> <y0> <x1> <y1>...
    - object-class: 0-based index
    - x/y: normalized polygon point

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -output <adams.core.io.PlaceholderFile> (property: output)
        The file to write the report to.
        default: ${TMP}/out.txt
     
    -finder <adams.data.objectfinder.ObjectFinder> (property: finder)
        The object finder to use.
        default: adams.data.objectfinder.AllFinder
     
    -label-key <java.lang.String> (property: labelKey)
        The key in the meta-data containing the label, ignored if empty.
        default:
     
    -width <int> (property: width)
        The width of the image to use when reading normalized coordinates/dimensions.
        default: 1000
        minimum: 1
     
    -height <int> (property: height)
        The height of the image to use when reading normalized coordinates/dimensions.
        default: 1000
        minimum: 1
     
    -label-definitions <adams.core.io.PlaceholderFile> (property: labelDefinitions)
        The spreadsheet file with the label index / label string relation.
        default: ${CWD}
     
    -label-reader <adams.data.io.input.SpreadSheetReader> (property: labelReader)
        The spreadsheet reader to use for the label definitions.
        default: adams.data.io.input.CsvSpreadSheetReader -data-row-type adams.data.spreadsheet.DenseDataRow -spreadsheet-type adams.data.spreadsheet.DefaultSpreadSheet
     
    -col-index <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colIndex)
        The spreadsheet column containing the 0-based label index.
        default: 1
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-label <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colLabel)
        The spreadsheet column containing the associated label string.
        default: 2
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -use-polygon-format <boolean> (property: usePolygonFormat)
        If enabled, outputs the data in polygon format rather than bbox format.
        default: false
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Finder

        protected ObjectFinder m_Finder
        the object finder to use.
      • m_LabelKey

        protected String m_LabelKey
        the meta-data key with the label.
      • m_Width

        protected int m_Width
        the image width to use as basis for normalized coordinates/dimensions.
      • m_Height

        protected int m_Height
        the image height to use as basis for normalized coordinates/dimensions.
      • m_LabelDefinitions

        protected PlaceholderFile m_LabelDefinitions
        the spreadsheet with the label index/label relation, ignored if directory.
      • m_LabelReader

        protected SpreadSheetReader m_LabelReader
        the spreadsheet reader to use.
      • m_UsePolygonFormat

        protected boolean m_UsePolygonFormat
        output polygon format rather than bbox format.
      • m_Labels

        protected transient Map<Integer,​String> m_Labels
        the label mapping.
      • m_LabelDefinitionsMonitor

        protected transient FileChangeMonitor m_LabelDefinitionsMonitor
        to monitor whether the file with the labels has changed.
    • Constructor Detail

      • YoloAnnotationsReportWriter

        public YoloAnnotationsReportWriter()
    • Method Detail

      • setFinder

        public void setFinder​(ObjectFinder value)
        Sets the finder to use for locating the objects.
        Parameters:
        value - the finder
      • getFinder

        public ObjectFinder getFinder()
        Returns the finder to use for locating the objects.
        Returns:
        the finder
      • finderTipText

        public String finderTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLabelKey

        public void setLabelKey​(String value)
        Sets the key in the meta-data containing the label.
        Parameters:
        value - the key
      • getLabelKey

        public String getLabelKey()
        Returns the key in the meta-data containing the label.
        Returns:
        the key
      • labelKeyTipText

        public String labelKeyTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setWidth

        public void setWidth​(int value)
        Sets the width of the image to use when reading normalized coordinates/dimensions.
        Parameters:
        value - the image width
      • getWidth

        public int getWidth()
        Returns the width of the image to use when reading normalized coordinates/dimensions.
        Returns:
        the image width
      • widthTipText

        public String widthTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setHeight

        public void setHeight​(int value)
        Sets the height of the image to use when reading normalized coordinates/dimensions.
        Parameters:
        value - the image height
      • getHeight

        public int getHeight()
        Returns the height of the image to use when reading normalized coordinates/dimensions.
        Returns:
        the image height
      • heightTipText

        public String heightTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLabelDefinitions

        public void setLabelDefinitions​(PlaceholderFile value)
        Sets the spreadsheet file with the label index / label string relation.
        Parameters:
        value - the file
      • getLabelDefinitions

        public PlaceholderFile getLabelDefinitions()
        Returns the spreadsheet file with the label index / label string relation.
        Returns:
        the file
      • labelDefinitionsTipText

        public String labelDefinitionsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLabelReader

        public void setLabelReader​(SpreadSheetReader value)
        Sets the spreadsheet reader to use for the definitions.
        Parameters:
        value - the reader
      • getLabelReader

        public SpreadSheetReader getLabelReader()
        Returns the spreadsheet reader to use for the definitions.
        Returns:
        the reader
      • labelReaderTipText

        public String labelReaderTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColIndex

        public void setColIndex​(SpreadSheetColumnIndex value)
        Sets the spreadsheet column containing the 0-based label index.
        Parameters:
        value - the file
      • getColIndex

        public SpreadSheetColumnIndex getColIndex()
        Returns the spreadsheet column containing the 0-based label index.
        Returns:
        the column
      • colIndexTipText

        public String colIndexTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColLabel

        public void setColLabel​(SpreadSheetColumnIndex value)
        Sets the spreadsheet column containing the 0-based label index.
        Parameters:
        value - the file
      • getColLabel

        public SpreadSheetColumnIndex getColLabel()
        Returns the spreadsheet column containing the 0-based label index.
        Returns:
        the column
      • colLabelTipText

        public String colLabelTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setUsePolygonFormat

        public void setUsePolygonFormat​(boolean value)
        Sets whether to use polygon format or bbox format.
        Parameters:
        value - true if to use
      • getUsePolygonFormat

        public boolean getUsePolygonFormat()
        Returns whether to use polygon format or bbox format.
        Returns:
        true if to use
      • usePolygonFormatTipText

        public String usePolygonFormatTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • convert

        protected List<String> convert​(Report data)
        Converts the report into yolo format lines.
        Parameters:
        data - the report to convert
        Returns:
        the generated yolo data
      • writeData

        protected boolean writeData​(Report data)
        Performs the actual writing.
        Specified by:
        writeData in class AbstractReportWriter<Report>
        Parameters:
        data - the data to write
        Returns:
        true if successfully written
      • write

        public String write​(Report data,
                            MessageCollection errors)
        Performs checks and converts the report to a string.
        Specified by:
        write in interface StringReportWriter<Report>
        Parameters:
        data - the data to write
        errors - for collecting errors
        Returns:
        the generated data, null in case of failure