Package adams.data.io.input
Class YoloAnnotationsReportReader
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.input.AbstractReportReader<Report>
-
- adams.data.io.input.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 Summary
Fields Modifier and Type Field Description protected SpreadSheetColumnIndex
m_ColIndex
the column with the label index.protected SpreadSheetColumnIndex
m_ColLabel
the column with the label string.protected int
m_Height
the image height to use as basis for normalized coordinates/dimensions.protected PlaceholderFile
m_LabelDefinitions
the spreadsheet with the label index/label relation, ignored if directory.protected FileChangeMonitor
m_LabelDefinitionsMonitor
to monitor whether the file with the labels has changed.protected SpreadSheetReader
m_LabelReader
the spreadsheet reader to use.protected Map<Integer,String>
m_Labels
the label mapping.protected String
m_LabelSuffix
the label suffix to use.protected String
m_Prefix
the prefix of the objects in the report.protected boolean
m_UsePolygonFormat
output polygon format rather than bbox format.protected int
m_Width
the image width to use as basis for normalized coordinates/dimensions.-
Fields inherited from class adams.data.io.input.AbstractReportReader
m_Input, m_Stopped
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description YoloAnnotationsReportReader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
colIndexTipText()
Returns the tip text for this property.String
colLabelTipText()
Returns the tip text for this property.protected List<Report>
convert(List<String> lines)
Converts the Yolo lines into a report.void
defineOptions()
Adds options to the internal list of options.protected int
determineParentID(Report report)
Tries to determine the parent ID for the current report.SpreadSheetColumnIndex
getColIndex()
Returns the spreadsheet column containing the 0-based label index.SpreadSheetColumnIndex
getColLabel()
Returns the spreadsheet column containing the 0-based label index.String
getFormatDescription()
Returns a string describing the format (used in the file chooser).String[]
getFormatExtensions()
Returns the extension(s) of the format.int
getHeight()
Returns the height of the image to use when reading normalized coordinates/dimensions.PlaceholderFile
getLabelDefinitions()
Returns the spreadsheet file with the label index / label string relation.SpreadSheetReader
getLabelReader()
Returns the spreadsheet reader to use for the definitions.String
getLabelSuffix()
Returns the field suffix used in the report for labels.String
getPrefix()
Returns the field prefix used in the report.boolean
getUsePolygonFormat()
Returns whether to use polygon format or bbox format.int
getWidth()
Returns the width of the image to use when reading normalized coordinates/dimensions.String
globalInfo()
Returns a string describing the object.String
heightTipText()
Returns the tip text for this property.String
labelDefinitionsTipText()
Returns the tip text for this property.String
labelReaderTipText()
Returns the tip text for this property.String
labelSuffixTipText()
Returns the tip text for this property.Report
newInstance()
Returns a new instance of the report class in use.String
prefixTipText()
Returns the tip text for this property.List<Report>
read(String s)
Reads the data.protected List<Report>
readData()
Performs the actual reading.static Map<Integer,String>
readLabelDefinitions(PlaceholderFile definitions, SpreadSheetReader reader, SpreadSheetColumnIndex index, SpreadSheetColumnIndex label)
Reads the label definitions, if the file exists.void
setColIndex(SpreadSheetColumnIndex value)
Sets the spreadsheet column containing the 0-based label index.void
setColLabel(SpreadSheetColumnIndex value)
Sets the spreadsheet column containing the 0-based label index.void
setHeight(int value)
Sets the height of the image to use when reading normalized coordinates/dimensions.void
setLabelDefinitions(PlaceholderFile value)
Sets the spreadsheet file with the label index / label string relation.void
setLabelReader(SpreadSheetReader value)
Sets the spreadsheet reader to use for the definitions.void
setLabelSuffix(String value)
Sets the field suffix used in the report for labels.void
setPrefix(String value)
Sets the field prefix used in the report.void
setUsePolygonFormat(boolean value)
Sets whether to use polygon format or bbox format.void
setWidth(int value)
Sets the width of the image to use when reading normalized coordinates/dimensions.String
usePolygonFormatTipText()
Returns the tip text for this property.String
widthTipText()
Returns the tip text for this property.-
Methods inherited from class adams.data.io.input.AbstractReportReader
checkData, cleanUp, compareTo, destroy, equals, forCommandLine, forName, getDefaultFormatExtension, getInput, getReaders, inputTipText, isStopped, postRead, read, reset, setInput, shallowCopy, shallowCopy, stopExecution
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.data.io.input.ReportReader
getInput, inputTipText, read, setInput
-
-
-
-
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_ColIndex
protected SpreadSheetColumnIndex m_ColIndex
the column with the label index.
-
m_ColLabel
protected SpreadSheetColumnIndex m_ColLabel
the column with the label string.
-
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_LabelDefinitionsMonitor
protected transient FileChangeMonitor m_LabelDefinitionsMonitor
to monitor whether the file with the labels has changed.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractReportReader<Report>
-
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 interfaceObjectPrefixHandler
- Parameters:
value
- the field prefix
-
getPrefix
public String getPrefix()
Returns the field prefix used in the report.- Specified by:
getPrefix
in interfaceObjectPrefixHandler
- Returns:
- the field prefix
-
prefixTipText
public String prefixTipText()
Returns the tip text for this property.- Specified by:
prefixTipText
in interfaceObjectPrefixHandler
- 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.
-
getFormatDescription
public String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescription
in interfaceFileFormatHandler
- Specified by:
getFormatDescription
in classAbstractReportReader<Report>
- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the extension(s) of the format.- Specified by:
getFormatExtensions
in interfaceFileFormatHandler
- Specified by:
getFormatExtensions
in classAbstractReportReader<Report>
- Returns:
- the extension(s) (without the dot!)
-
determineParentID
protected int determineParentID(Report report)
Tries to determine the parent ID for the current report.- Specified by:
determineParentID
in classAbstractReportReader<Report>
- Parameters:
report
- the report to determine the ID for- Returns:
- the parent database ID, -1 if it cannot be determined
-
newInstance
public Report newInstance()
Returns a new instance of the report class in use.- Specified by:
newInstance
in classAbstractReportReader<Report>
- Returns:
- the new (empty) report
-
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)
-
readData
protected List<Report> readData()
Performs the actual reading.- Specified by:
readData
in classAbstractReportReader<Report>
- Returns:
- the reports that were read
-
read
public List<Report> read(String s)
Reads the data.- Specified by:
read
in interfaceStringReportReader<Report>
- Parameters:
s
- the string to read from- Returns:
- the report loaded from the string
-
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 filereader
- the spreadsheet reader to useindex
- the column with the 0-based label indexlabel
- the column with the label string- Returns:
- the mapping, null if nothing to read
-
-