Repository navigation
DiGi.YOLO.Classes
Represents a rectangular bounding box used to define the location and size of an object within an image.
public class BoundingBox : DiGi.YOLO.Interfaces.IBoundingBoxInheritance System.Object → BoundingBox
Derived
↳ BoundingBoxResult
Implements IBoundingBox
Initializes a new instance of the BoundingBox class.
public BoundingBox(double x, double y, double width, double height);The x-coordinate of the top-left corner of the bounding box.
The y-coordinate of the top-left corner of the bounding box.
width System.Double
The width of the bounding box.
height System.Double
The height of the bounding box.
Gets the height of the bounding box.
public double Height { get; }Implements Height
Gets the width of the bounding box.
public double Width { get; }Implements Width
Gets the x-coordinate of the top-left corner of the bounding box.
public double X { get; }Implements X
Gets the y-coordinate of the top-left corner of the bounding box.
public double Y { get; }Implements Y
Determines whether the specified object is equal to the current bounding box based on its coordinates and dimensions.
public override bool Equals(object? @object);object System.Object
The object to compare with the current bounding box.
System.Boolean
True if the objects are equal; otherwise, false.
Returns a hash code for the current bounding box based on its coordinates and dimensions.
public override int GetHashCode();System.Int32
A hash code for the current object.
Returns a string that represents the current bounding box in the format "x y width height".
public override string ToString();System.String
A string representation of the bounding box.
Represents the result of a bounding box detection, containing spatial coordinates, label information, and confidence score.
public class BoundingBoxResult : DiGi.YOLO.Classes.BoundingBoxInheritance System.Object → BoundingBox → BoundingBoxResult
Initializes a new instance of the BoundingBoxResult class.
public BoundingBoxResult(string? name, int labelIndex, double x, double y, double width, double height, double confidence);name System.String
The name of the detected object.
labelIndex System.Int32
The index of the label associated with the detection.
The X coordinate of the bounding box.
The Y coordinate of the bounding box.
width System.Double
The width of the bounding box.
height System.Double
The height of the bounding box.
confidence System.Double
The confidence score of the detection.
Gets the confidence score of the detected object.
public double Confidence { get; }Gets the index of the label for the detected object.
public int LabelIndex { get; }Gets the name of the detected object.
public string? Name { get; }Determines whether the specified object is equal to the current bounding box result based on its properties.
public override bool Equals(object? @object);object System.Object
The object to compare with the current object.
System.Boolean
true if the objects are equal; otherwise, false.
Gets the hash code for the current bounding box result.
public override int GetHashCode();System.Int32
A 32-bit signed integer hash code.
Returns a string representation of the bounding box result, including name, label index, coordinates, dimensions, and confidence.
public override string ToString();System.String
A tab-separated string containing the detection details.
Represents a collection of bounding box results typically associated with a result file.
public class BoundingBoxResultFile : System.Collections.Generic.List<DiGi.YOLO.Classes.BoundingBoxResult>Inheritance System.Object → System.Collections.Generic.List<BoundingBoxResult> → BoundingBoxResultFile
Initializes a new instance of the BoundingBoxResultFile class.
public BoundingBoxResultFile();Returns a string representation of the bounding box results contained in the file, with each result on a new line.
public override string? ToString();System.String
A string containing the concatenated string representations of all valid bounding box results.
Represents the configuration settings for a YOLO project, including directory paths and labels.
public class ConfigurationFileInheritance System.Object → ConfigurationFile
Initializes a new instance of the ConfigurationFile class.
public ConfigurationFile();Initializes a new instance of the ConfigurationFile class with specified directory paths and labels.
public ConfigurationFile(string? directory, string? trainDirectoryName, string? validateDirectoryName, string? testDirectoryName, System.Collections.Generic.IEnumerable<DiGi.YOLO.Classes.Label>? labels);directory System.String
The base root directory path.
trainDirectoryName System.String
The relative name of the training directory.
validateDirectoryName System.String
The relative name of the validation directory.
testDirectoryName System.String
The relative name of the test directory.
labels System.Collections.Generic.IEnumerable<Label>
A collection of labels to be associated with this configuration.
Gets the base root directory path.
public string? Directory { get; }Gets the collection of labels associated with this configuration.
public System.Collections.Generic.IEnumerable<DiGi.YOLO.Classes.Label> Labels { get; }System.Collections.Generic.IEnumerable<Label>
Retrieves all categories defined within the configuration.
public System.Collections.Generic.IEnumerable<DiGi.YOLO.Enums.Category> GetCategories();System.Collections.Generic.IEnumerable<Category>
An enumerable collection of Category values.
Gets the full combined path for a specific category.
public string? GetDirectory(DiGi.YOLO.Enums.Category category);category Category
The category for which to retrieve the full directory path.
System.String
The absolute path combining the base directory and the category folder, or null if not found or empty.
Gets the relative directory name for a specific category.
public string? GetDirectoryNames(DiGi.YOLO.Enums.Category category);category Category
The category for which to retrieve the folder name.
System.String
The relative directory name, or null if not found or empty.
Returns a string representation of the configuration file, formatted for output or storage.
public override string? ToString();System.String
A formatted string containing the base path, category paths, and label names.
Represents an image associated with a collection of BoundingBox instances.
public class Image : DiGi.YOLO.Classes.Image<DiGi.YOLO.Classes.BoundingBox>Inheritance System.Object → DiGi.YOLO.Classes.Image<BoundingBox> → Image
Initializes a new instance of the Image class.
public Image(string? path);path System.String
The file path to the image.
Creates and populates a LabelFile containing all bounding boxes associated with this image.
public DiGi.YOLO.Classes.LabelFile GetLabelFile();LabelFile
A LabelFile instance populated with the image's bounding box data.
Represents an image associated with a collection of bounding boxes categorized by label indices.
public class Image<TBoundingBox>
where TBoundingBox : DiGi.YOLO.Interfaces.IBoundingBoxTBoundingBox
The type of the bounding box, which must implement IBoundingBox.
Inheritance System.Object → Image<TBoundingBox>
Derived
↳ Image
Initializes a new instance of the Image<TBoundingBox> class.
public Image(string? path);path System.String
The file path to the image.
The dictionary containing bounding boxes grouped by label indices.
protected Dictionary<int,HashSet<TBoundingBox>> boundingBoxes;System.Collections.Generic.Dictionary<System.Int32,System.Collections.Generic.HashSet<TBoundingBox>>
The file path to the image.
protected string? path;Gets the collection of label indices that have associated bounding boxes in this image.
public System.Collections.Generic.IEnumerable<int> LabelIndexes { get; }System.Collections.Generic.IEnumerable<System.Int32>
Gets the file path of the image.
public string? Path { get; }Gets the set of bounding boxes associated with the specified label index.
public System.Collections.Generic.IEnumerable<TBoundingBox>? this[int labelIndex] { get; }labelIndex System.Int32
The index of the label to retrieve bounding boxes for.
System.Collections.Generic.IEnumerable<TBoundingBox>
Adds a bounding box to the image for the specified label index.
public bool Add(int labelIndex, TBoundingBox? boundingBox);labelIndex System.Int32
The index of the label.
boundingBox TBoundingBox
The bounding box instance to add.
System.Boolean
True if the bounding box was successfully added; otherwise, false.
Represents a label associated with an object detection class in YOLO.
public class LabelInheritance System.Object → Label
Initializes a new instance of the Label class.
public Label(int index, string? name);index System.Int32
The numerical index for the label.
name System.String
The descriptive name for the label.
The numerical index of the label.
public int index;The descriptive name of the label.
public string? name;Gets the numerical index of the label.
public int Index { get; }Gets the descriptive name of the label.
public string? Name { get; }Determines whether the specified object is equal to the current label based on its string representation.
public override bool Equals(object @object);object System.Object
The object to compare with the current label.
System.Boolean
True if the objects are equal; otherwise, false.
Returns a hash code for the current label based on its string representation.
public override int GetHashCode();System.Int32
A 32-bit signed integer hash code.
Returns a string that represents the current label.
public override string ToString();System.String
A string containing the index and name of the label.
Represents a label file containing associations between class indices and bounding boxes for an image.
public class LabelFileInheritance System.Object → LabelFile
Initializes a new instance of the LabelFile class.
public LabelFile();The collection of tuples pairing label indices with their corresponding bounding boxes.
public List<Tuple<int,BoundingBox>> tuples;System.Collections.Generic.List<System.Tuple<System.Int32,BoundingBox>>
Gets the total number of entries in the label file.
public int Count { get; }Adds a label index and its associated bounding box to the collection.
public bool Add(int labelIndex, DiGi.YOLO.Classes.BoundingBox? boundingBox);labelIndex System.Int32
The integer index of the label.
boundingBox BoundingBox
The bounding box associated with the label.
System.Boolean
True if the pair was successfully added; otherwise, false if the bounding box is null or the index is negative.
Retrieves the bounding box at the specified position.
public DiGi.YOLO.Classes.BoundingBox GetBoundingBox(int index);index System.Int32
The zero-based index of the entry to retrieve.
BoundingBox
The BoundingBox associated with the given position.
Retrieves all bounding boxes associated with a specific label index.
public System.Collections.Generic.List<DiGi.YOLO.Classes.BoundingBox> GetBoundingBoxes(int labelIndex);labelIndex System.Int32
The label index to filter by.
System.Collections.Generic.List<BoundingBox>
A list of BoundingBox objects matching the specified label index.
Retrieves the label index at the specified position.
public int GetLabelIndex(int index);index System.Int32
The zero-based index of the entry to retrieve.
System.Int32
The label index associated with the given position.
Retrieves a set of all unique tag indices present in the label file.
public System.Collections.Generic.HashSet<int> GetTagIndexes();System.Collections.Generic.HashSet<System.Int32>
A System.Collections.Generic.HashSet<> containing the unique label indices.
Returns a string representation of the label file, formatted as space-separated values per line.
public override string ToString();System.String
A string containing the labels and bounding boxes separated by new lines.
Represents a YOLO model structure that manages images, labels, and their associated categories and bounding boxes.
public class YOLOModelInheritance System.Object → YOLOModel
Initializes a new instance of the YOLOModel class and sets up default directory paths for train, validate, and test categories.
public YOLOModel();Initializes a new instance of the YOLOModel class using the provided configuration file.
public YOLOModel(DiGi.YOLO.Classes.ConfigurationFile? configurationFile);configurationFile ConfigurationFile
The configuration file to initialize the model with.
Initializes a new instance of the YOLOModel class with a specified root directory and sets up default category paths.
public YOLOModel(string? directory);directory System.String
The base directory path for the model.
Gets or sets the base directory path for the model data.
public string? Directory { get; set; }Adds the specified configuration file settings to the YOLO model.
public bool Add(DiGi.YOLO.Classes.ConfigurationFile? configurationFile);configurationFile ConfigurationFile
The configuration file containing directory and label information.
System.Boolean
True if the configuration was successfully added; otherwise, false.
Adds a specific Label object to the model's labels collection.
public bool Add(DiGi.YOLO.Classes.Label? label);label Label
The label object to add.
System.Boolean
True if the label was successfully added; otherwise, false.
Adds a new label name to the model's labels collection if it does not already exist.
public bool Add(string? labelName);labelName System.String
The name of the label to add.
System.Boolean
True if the label was added; false if the label already exists or is invalid.
Adds all labels and bounding boxes contained within a label file to an image at the given path.
public bool Add(string? path, DiGi.YOLO.Classes.LabelFile? labelFile);path System.String
The file path of the image.
labelFile LabelFile
The label file containing annotation data.
System.Boolean
True if at least one bounding box was successfully added; otherwise, false.
Associates an image at the specified path with one or more categories.
public bool Add(string? path, params DiGi.YOLO.Enums.Category[]? categories);path System.String
The file path of the image.
An array of categories to assign to the image.
System.Boolean
True if the image and categories were successfully added; otherwise, false.
Adds a bounding box for a specific label to an image at the given path.
public bool Add(string? path, string? labelName, DiGi.YOLO.Classes.BoundingBox? boundingBox);path System.String
The file path of the image.
labelName System.String
The name of the label associated with the bounding box.
boundingBox BoundingBox
The bounding box coordinates and dimensions.
System.Boolean
True if the bounding box was successfully added to the image; otherwise, false.
Retrieves a collection of all unique categories currently stored in the model.
public System.Collections.Generic.IEnumerable<DiGi.YOLO.Enums.Category>? GetCategories();System.Collections.Generic.IEnumerable<Category>
An enumerable containing all registered Category values.
Retrieves the collection of categories associated with the specified path.
public System.Collections.Generic.IEnumerable<DiGi.YOLO.Enums.Category>? GetCategories(string? path);path System.String
The directory path to look up categories for.
System.Collections.Generic.IEnumerable<Category>
An enumerable of Category if found; otherwise, null.
Creates and returns a ConfigurationFile instance based on the current model configuration.
public DiGi.YOLO.Classes.ConfigurationFile? GetConfigurationFile();ConfigurationFile
A ConfigurationFile object representing the current settings.
Retrieves the full path to the base images directory.
public string? GetDirectory_Images();System.String
The combined path string if the base directory is set; otherwise, null.
Retrieves the full path to the images directory for the specified category using the model's current base directory.
public string? GetDirectory_Images(DiGi.YOLO.Enums.Category category);category Category
The category (e.g., Train, Validate, Test) to locate.
System.String
The combined path string if successful; otherwise, null.
Retrieves the full path to the images directory for a specific category within a provided root directory.
public string? GetDirectory_Images(string? directory, DiGi.YOLO.Enums.Category category);directory System.String
The root directory path.
category Category
The category (e.g., Train, Validate, Test) to locate.
System.String
The combined path string if the root directory is valid; otherwise, null.
Retrieves the full path to the labels directory by deriving it from the images directory path.
public string? GetDirectory_Labels();System.String
The combined path string for labels if successful; otherwise, null.
Retrieves the labels directory path for a specific category using the model's internal directory state.
public string? GetDirectory_Labels(DiGi.YOLO.Enums.Category category);category Category
The category associated with the directories.
System.String
The calculated path to the labels directory, or null.
Retrieves the labels directory path based on a provided image directory and category.
public string? GetDirectory_Labels(string? directory, DiGi.YOLO.Enums.Category category);directory System.String
The base directory path to evaluate.
category Category
The category associated with the directories.
System.String
The calculated path to the labels directory, or null if the provided directory is null or whitespace.
Retrieves an image object associated with the specified file path.
public DiGi.YOLO.Classes.Image? GetImage(string? path);path System.String
The file path of the image.
Image
The Image object if found in the model; otherwise, null.
Retrieves all images that belong to a specific category.
public System.Collections.Generic.IEnumerable<DiGi.YOLO.Classes.Image> GetImages(DiGi.YOLO.Enums.Category category);category Category
The category used to filter the images.
System.Collections.Generic.IEnumerable<Image>
An enumerable collection of Image objects belonging to the specified category.
Retrieves a label based on its unique integer index.
public DiGi.YOLO.Classes.Label? GetLabel(int labelIndex);labelIndex System.Int32
The index of the label to retrieve.
Label
The Label object if found; otherwise, null.
Retrieves the label file associated with the image at the specified path.
public DiGi.YOLO.Classes.LabelFile? GetLabelFile(string? path);path System.String
The file path of the image.
LabelFile
The LabelFile object if found; otherwise, null.
Retrieves all labels defined within the model.
public System.Collections.Generic.IEnumerable<DiGi.YOLO.Classes.Label> GetLabels();System.Collections.Generic.IEnumerable<Label>
An enumerable collection of all available Label objects.
Retrieves all labels associated with the image at the specified path.
public System.Collections.Generic.IEnumerable<DiGi.YOLO.Classes.Label>? GetLabels(string? path);path System.String
The file path of the image.
System.Collections.Generic.IEnumerable<Label>
An enumerable collection of Label objects associated with the image, or null if no labels are found.
Retrieves the index of a label based on its name.
public int LabelIndex(string? labelName);labelName System.String
The name of the label to search for.
System.Int32
The integer index of the label if found; otherwise, -1.
Provides the settings one run of the YOLO prediction script needs: which interpreter runs it, which weights it scores with, which images it reads, and where it writes its results.
The constructors only assign. Use YOLOPredictionOptions(string, string, string, string, string, double) to resolve the interpreter, tidy the paths and reject a combination that cannot make a run.
public class YOLOPredictionOptions : DiGi.Core.Classes.SerializableOptions, DiGi.YOLO.Interfaces.IYOLOSerializableObject, DiGi.YOLO.Interfaces.IYOLOObject, DiGi.Core.Interfaces.IObject, DiGi.Core.Interfaces.ISerializableObject, DiGi.Core.Interfaces.ICloneableObject<DiGi.Core.Interfaces.ISerializableObject>, DiGi.Core.Interfaces.ICloneableObjectInheritance System.Object → DiGi.Core.Classes.Object → DiGi.Core.Classes.SerializableObject → DiGi.Core.Classes.SerializableOptions → YOLOPredictionOptions
Implements IYOLOSerializableObject, IYOLOObject, DiGi.Core.Interfaces.IObject, DiGi.Core.Interfaces.ISerializableObject, DiGi.Core.Interfaces.ICloneableObject<DiGi.Core.Interfaces.ISerializableObject>, DiGi.Core.Interfaces.ICloneableObject
Initializes a new instance of the YOLOPredictionOptions class with default values.
public YOLOPredictionOptions();Initializes a new instance of the YOLOPredictionOptions class by copying an existing options instance.
public YOLOPredictionOptions(DiGi.YOLO.Classes.YOLOPredictionOptions? yOLOPredictionOptions);yOLOPredictionOptions YOLOPredictionOptions
The source options instance to copy from.
Initializes a new instance of the YOLOPredictionOptions class using a JSON object.
public YOLOPredictionOptions(System.Text.Json.Nodes.JsonObject? jsonObject);jsonObject System.Text.Json.Nodes.JsonObject
The JSON object containing the configuration settings.
Gets or sets the confidence threshold a detection has to reach to be reported, passed to predict.py as --conf.
The default matches the script's own default. Lowering it returns more boxes and more false positives; the weights are frozen, so this is the only knob over how much the detector reports.
public double Confidence { get; set; }Gets or sets the path of the trained weights file the prediction scores with, passed to predict.py as --model.
Left null the script falls back to its own search, which picks whichever training run is newest on disk. Name the file, so a run is reproducible.
public string? ModelPath { get; set; }Gets or sets the path of the bounding box result file the prediction writes, passed to predict.py as --output.
The script opens it for writing rather than appending, so re-running a source directory replaces the previous answer instead of doubling it.
public string? OutputPath { get; set; }Gets or sets the path of the CPython interpreter that runs the prediction script, or the name of one on PATH.
This has to be CPython with ultralytics and torch installed. The IronPython engine in DiGi.Scripting.Python cannot host either of them.
public string? PythonPath { get; set; }Gets or sets the directory holding the images to score, passed to predict.py as --source.
The script reads the .jpg, .jpeg and .png files directly in the directory and does not descend into it.
public string? SourceDirectory { get; set; }Gets or sets the directory the prediction process runs in, which is also where the runner keeps the Python scripts.
predict.py imports utils.py, and Python resolves that import against the directory the script itself sits in, so the two files have to stay together. The runner puts them there with WriteScripts(string) when they are missing. Ultralytics also writes its own caches here.
public string? WorkingDirectory { get; set; }Represents what one run of the YOLO prediction script did: how it ended, what it said, and the result lines it produced.
The detections are kept as the raw lines of the bounding box result file rather than as parsed objects, so that a result read back from JSON is the same result that was written. Parse them with BoundingBoxResultFile(this YOLOPredictionResult).
public class YOLOPredictionResult : DiGi.Core.Classes.SerializableResult, DiGi.YOLO.Interfaces.IYOLOSerializableObject, DiGi.YOLO.Interfaces.IYOLOObject, DiGi.Core.Interfaces.IObject, DiGi.Core.Interfaces.ISerializableObject, DiGi.Core.Interfaces.ICloneableObject<DiGi.Core.Interfaces.ISerializableObject>, DiGi.Core.Interfaces.ICloneableObjectInheritance System.Object → DiGi.Core.Classes.Object → DiGi.Core.Classes.SerializableObject → DiGi.Core.Classes.SerializableResult → YOLOPredictionResult
Implements IYOLOSerializableObject, IYOLOObject, DiGi.Core.Interfaces.IObject, DiGi.Core.Interfaces.ISerializableObject, DiGi.Core.Interfaces.ICloneableObject<DiGi.Core.Interfaces.ISerializableObject>, DiGi.Core.Interfaces.ICloneableObject
Initializes a new instance of the YOLOPredictionResult class by copying an existing result.
public YOLOPredictionResult(DiGi.YOLO.Classes.YOLOPredictionResult? yOLOPredictionResult);yOLOPredictionResult YOLOPredictionResult
The source result to copy from.
YOLOPredictionResult(int, int, string, IEnumerable<string>, IEnumerable<string>, IEnumerable<string>, Nullable<DateTimeOffset>, Nullable<DateTimeOffset>) Constructor
Initializes a new instance of the YOLOPredictionResult class.
public YOLOPredictionResult(int exitCode, int imageCount, string? outputPath, System.Collections.Generic.IEnumerable<string>? values, System.Collections.Generic.IEnumerable<string>? standardOutput, System.Collections.Generic.IEnumerable<string>? standardError, System.Nullable<System.DateTimeOffset> start, System.Nullable<System.DateTimeOffset> end);exitCode System.Int32
The code the prediction process ended with, or -1 when the runner never got one.
imageCount System.Int32
The number of images found in the source directory.
outputPath System.String
The path of the bounding box result file the run was told to write.
values System.Collections.Generic.IEnumerable<System.String>
The lines of the bounding box result file the run produced.
standardOutput System.Collections.Generic.IEnumerable<System.String>
The trailing lines the process wrote to its standard output stream.
standardError System.Collections.Generic.IEnumerable<System.String>
The trailing lines the process wrote to its standard error stream.
start System.Nullable<System.DateTimeOffset>
The moment the run began.
end System.Nullable<System.DateTimeOffset>
The moment the run ended.
Initializes a new instance of the YOLOPredictionResult class using a JSON object.
public YOLOPredictionResult(System.Text.Json.Nodes.JsonObject? jsonObject);jsonObject System.Text.Json.Nodes.JsonObject
The JSON object containing the result data.
Gets how long the run took, or null when either end of it is unknown.
public System.Nullable<System.TimeSpan> Duration { get; }System.Nullable<System.TimeSpan>
Gets the moment the run ended.
public System.Nullable<System.DateTimeOffset> End { get; }System.Nullable<System.DateTimeOffset>
Gets the code the prediction process ended with. Zero means it ran to completion.
-1 is the runner's own code for a run it never handed to the interpreter or took back from it - the process could not be started, the source directory was gone, or the run was cancelled. StandardError carries the reason in the first two cases; a caller that cancelled already knows about the third.
public int ExitCode { get; }Gets the number of images found in the source directory.
Zero here with an exit code of zero is a run that had nothing to do, which is worth telling apart from a run that scored images and found nothing on them.
public int ImageCount { get; }Gets the path of the bounding box result file the run was told to write.
public string? OutputPath { get; }Gets the trailing lines the process wrote to its standard error stream, at most OutputLines of them.
public System.Collections.Generic.List<string>? StandardError { get; }System.Collections.Generic.List<System.String>
Gets the trailing lines the process wrote to its standard output stream, at most OutputLines of them.
public System.Collections.Generic.List<string>? StandardOutput { get; }System.Collections.Generic.List<System.String>
Gets the moment the run began.
public System.Nullable<System.DateTimeOffset> Start { get; }System.Nullable<System.DateTimeOffset>
Gets a value indicating whether the run completed and produced its result file.
public bool Succeeded { get; }Gets the lines of the bounding box result file the run produced, or null when it produced none.
An empty list is a run that scored images and detected nothing; null is a run that wrote no file at all.
public System.Collections.Generic.List<string>? Values { get; }