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 SpreadSheetColumnIndexm_ColIndexthe column with the label index.protected SpreadSheetColumnIndexm_ColLabelthe column with the label string.protected intm_Heightthe image height to use as basis for normalized coordinates/dimensions.protected PlaceholderFilem_LabelDefinitionsthe spreadsheet with the label index/label relation, ignored if directory.protected FileChangeMonitorm_LabelDefinitionsMonitorto monitor whether the file with the labels has changed.protected SpreadSheetReaderm_LabelReaderthe spreadsheet reader to use.protected Map<Integer,String>m_Labelsthe label mapping.protected Stringm_LabelSuffixthe label suffix to use.protected Stringm_Prefixthe prefix of the objects in the report.protected booleanm_UsePolygonFormatoutput polygon format rather than bbox format.protected intm_Widththe 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 StringcolIndexTipText()Returns the tip text for this property.StringcolLabelTipText()Returns the tip text for this property.protected List<Report>convert(List<String> lines)Converts the Yolo lines into a report.voiddefineOptions()Adds options to the internal list of options.protected intdetermineParentID(Report report)Tries to determine the parent ID for the current report.SpreadSheetColumnIndexgetColIndex()Returns the spreadsheet column containing the 0-based label index.SpreadSheetColumnIndexgetColLabel()Returns the spreadsheet column containing the 0-based label index.StringgetFormatDescription()Returns a string describing the format (used in the file chooser).String[]getFormatExtensions()Returns the extension(s) of the format.intgetHeight()Returns the height of the image to use when reading normalized coordinates/dimensions.PlaceholderFilegetLabelDefinitions()Returns the spreadsheet file with the label index / label string relation.SpreadSheetReadergetLabelReader()Returns the spreadsheet reader to use for the definitions.StringgetLabelSuffix()Returns the field suffix used in the report for labels.StringgetPrefix()Returns the field prefix used in the report.booleangetUsePolygonFormat()Returns whether to use polygon format or bbox format.intgetWidth()Returns the width of the image to use when reading normalized coordinates/dimensions.StringglobalInfo()Returns a string describing the object.StringheightTipText()Returns the tip text for this property.StringlabelDefinitionsTipText()Returns the tip text for this property.StringlabelReaderTipText()Returns the tip text for this property.StringlabelSuffixTipText()Returns the tip text for this property.ReportnewInstance()Returns a new instance of the report class in use.StringprefixTipText()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.voidsetColIndex(SpreadSheetColumnIndex value)Sets the spreadsheet column containing the 0-based label index.voidsetColLabel(SpreadSheetColumnIndex value)Sets the spreadsheet column containing the 0-based label index.voidsetHeight(int value)Sets the height of the image to use when reading normalized coordinates/dimensions.voidsetLabelDefinitions(PlaceholderFile value)Sets the spreadsheet file with the label index / label string relation.voidsetLabelReader(SpreadSheetReader value)Sets the spreadsheet reader to use for the definitions.voidsetLabelSuffix(String value)Sets the field suffix used in the report for labels.voidsetPrefix(String value)Sets the field prefix used in the report.voidsetUsePolygonFormat(boolean value)Sets whether to use polygon format or bbox format.voidsetWidth(int value)Sets the width of the image to use when reading normalized coordinates/dimensions.StringusePolygonFormatTipText()Returns the tip text for this property.StringwidthTipText()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:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin 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:
setPrefixin interfaceObjectPrefixHandler- Parameters:
value- the field prefix
-
getPrefix
public String getPrefix()
Returns the field prefix used in the report.- Specified by:
getPrefixin interfaceObjectPrefixHandler- Returns:
- the field prefix
-
prefixTipText
public String prefixTipText()
Returns the tip text for this property.- Specified by:
prefixTipTextin 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:
getFormatDescriptionin interfaceFileFormatHandler- Specified by:
getFormatDescriptionin 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:
getFormatExtensionsin interfaceFileFormatHandler- Specified by:
getFormatExtensionsin 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:
determineParentIDin 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:
newInstancein 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:
readDatain classAbstractReportReader<Report>- Returns:
- the reports that were read
-
read
public List<Report> read(String s)
Reads the data.- Specified by:
readin 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
-
-