Class YoloAnnotationsReportReader

  • All Implemented Interfaces:
    CleanUpHandler, Destroyable, GlobalInfoSupporter, FileFormatHandler, LoggingLevelHandler, LoggingSupporter, OptionHandler, ShallowCopySupporter<AbstractReportReader>, SizeOfHandler, Stoppable, StoppableWithFeedback, ReportReader<Report>, StringReportReader<Report>, ObjectPrefixHandler, Serializable, Comparable

    public class YoloAnnotationsReportReader
    extends AbstractReportReader<Report>
    implements ObjectPrefixHandler, StringReportReader<Report>
    Reads 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
        min-user-mode: Expert
     
    -input <adams.core.io.PlaceholderFile> (property: input)
        The file to read and turn into a report.
        default: ${CWD}
     
    -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.
     
    -prefix <java.lang.String> (property: prefix)
        The report field prefix used in the report.
        default: Object.
     
    -label-suffix <java.lang.String> (property: labelSuffix)
        The suffix to use in the report for labels.
        default: type
     
    -use-polygon-format <boolean> (property: usePolygonFormat)
        If enabled, assumes that the data is in polygon format rather than auto-detecting
        bbox/polygon format.
        default: false
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • 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_Prefix

        protected String m_Prefix
        the prefix of the objects in the report.
      • m_LabelSuffix

        protected String m_LabelSuffix
        the label suffix 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

      • YoloAnnotationsReportReader

        public YoloAnnotationsReportReader()
    • Method Detail

      • 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.
      • setPrefix

        public void setPrefix​(String value)
        Sets the field prefix used in the report.
        Specified by:
        setPrefix in interface ObjectPrefixHandler
        Parameters:
        value - the field prefix
      • prefixTipText

        public String prefixTipText()
        Returns the tip text for this property.
        Specified by:
        prefixTipText in interface ObjectPrefixHandler
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLabelSuffix

        public void setLabelSuffix​(String value)
        Sets the field suffix used in the report for labels.
        Parameters:
        value - the field suffix
      • getLabelSuffix

        public String getLabelSuffix()
        Returns the field suffix used in the report for labels.
        Returns:
        the field suffix
      • labelSuffixTipText

        public String labelSuffixTipText()
        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.
      • determineParentID

        protected int determineParentID​(Report report)
        Tries to determine the parent ID for the current report.
        Specified by:
        determineParentID in class AbstractReportReader<Report>
        Parameters:
        report - the report to determine the ID for
        Returns:
        the parent database ID, -1 if it cannot be determined
      • convert

        protected List<Report> convert​(List<String> lines)
        Converts the Yolo lines into a report.
        Parameters:
        lines - the yolo annotations to convert
        Returns:
        the generated report(s)
      • readLabelDefinitions

        public static Map<Integer,​String> readLabelDefinitions​(PlaceholderFile definitions,
                                                                     SpreadSheetReader reader,
                                                                     SpreadSheetColumnIndex index,
                                                                     SpreadSheetColumnIndex label)
        Reads the label definitions, if the file exists.
        Parameters:
        definitions - the definitions file
        reader - the spreadsheet reader to use
        index - the column with the 0-based label index
        label - the column with the label string
        Returns:
        the mapping, null if nothing to read