Package adams.data.io.output
Class YoloAnnotationsReportWriter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractReportWriter<Report>
-
- adams.data.io.output.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 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 ObjectFinder
m_Finder
the object finder to use.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 String
m_LabelKey
the meta-data key with the label.protected SpreadSheetReader
m_LabelReader
the spreadsheet reader to use.protected Map<Integer,String>
m_Labels
the label mapping.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.output.AbstractReportWriter
m_Output
-
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 YoloAnnotationsReportWriter()
-
Method Summary
All 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<String>
convert(Report data)
Converts the report into yolo format lines.void
defineOptions()
Adds options to the internal list of options.String
finderTipText()
Returns the tip text for this property.SpreadSheetColumnIndex
getColIndex()
Returns the spreadsheet column containing the 0-based label index.SpreadSheetColumnIndex
getColLabel()
Returns the spreadsheet column containing the 0-based label index.ObjectFinder
getFinder()
Returns the finder to use for locating the objects.String
getFormatDescription()
Returns a string describing the format (used in the file chooser).String[]
getFormatExtensions()
Returns the extension 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.String
getLabelKey()
Returns the key in the meta-data containing the label.SpreadSheetReader
getLabelReader()
Returns the spreadsheet reader to use for the definitions.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
labelKeyTipText()
Returns the tip text for this property.String
labelReaderTipText()
Returns the tip text for this property.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
setFinder(ObjectFinder value)
Sets the finder to use for locating the objects.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
setLabelKey(String value)
Sets the key in the meta-data containing the label.void
setLabelReader(SpreadSheetReader value)
Sets the spreadsheet reader to use for the definitions.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.String
write(Report data, MessageCollection errors)
Performs checks and converts the report to a string.protected boolean
writeData(Report data)
Performs the actual writing.-
Methods inherited from class adams.data.io.output.AbstractReportWriter
checkData, cleanUp, compareTo, destroy, equals, forCommandLine, forName, getDefaultFormatExtension, getOutput, getWriters, outputTipText, reset, setOutput, shallowCopy, shallowCopy, write
-
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.output.ReportWriter
getOutput, outputTipText, setOutput, write
-
-
-
-
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_ColIndex
protected SpreadSheetColumnIndex m_ColIndex
the column with the label index.
-
m_ColLabel
protected SpreadSheetColumnIndex m_ColLabel
the column with the label string.
-
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 classAbstractReportWriter<Report>
-
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.
-
getFormatDescription
public String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescription
in interfaceFileFormatHandler
- Specified by:
getFormatDescription
in classAbstractReportWriter<Report>
- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the extension of the format.- Specified by:
getFormatExtensions
in interfaceFileFormatHandler
- Specified by:
getFormatExtensions
in classAbstractReportWriter<Report>
- Returns:
- the extension (without the dot!)
-
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 classAbstractReportWriter<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 interfaceStringReportWriter<Report>
- Parameters:
data
- the data to writeerrors
- for collecting errors- Returns:
- the generated data, null in case of failure
-
-