Rename
editorconfig
This commit is contained in:
@ -12,7 +12,7 @@ internal sealed class CnnFaceDetectionModelV1
|
||||
public static IEnumerable<MModRect> Detect(LossMmod net, Image image, int upsampleNumTimes)
|
||||
{
|
||||
using PyramidDown? pyr = new(2);
|
||||
List<MModRect>? rects = new();
|
||||
List<MModRect>? rects = [];
|
||||
|
||||
// Copy the data into dlib based objects
|
||||
using Matrix<RgbPixel>? matrix = new();
|
||||
@ -52,8 +52,8 @@ internal sealed class CnnFaceDetectionModelV1
|
||||
|
||||
public static IEnumerable<IEnumerable<MModRect>> DetectMulti(LossMmod net, IEnumerable<Image> images, int upsampleNumTimes, int batchSize = 128)
|
||||
{
|
||||
List<Matrix<RgbPixel>>? destImages = new();
|
||||
List<IEnumerable<MModRect>>? allRects = new();
|
||||
List<Matrix<RgbPixel>>? destImages = [];
|
||||
List<IEnumerable<MModRect>>? allRects = [];
|
||||
|
||||
try
|
||||
{
|
||||
@ -86,7 +86,7 @@ internal sealed class CnnFaceDetectionModelV1
|
||||
OutputLabels<IEnumerable<MModRect>>? dets = net.Operator(destImages, (ulong)batchSize);
|
||||
foreach (IEnumerable<MModRect>? det in dets)
|
||||
{
|
||||
List<MModRect>? rects = new();
|
||||
List<MModRect>? rects = [];
|
||||
foreach (MModRect? d in det)
|
||||
{
|
||||
DRectangle drect = pyr.RectDown(new DRectangle(d.Rect), (uint)upsampleNumTimes);
|
||||
|
@ -10,14 +10,14 @@ internal sealed class FaceRecognitionModelV1
|
||||
|
||||
public static Matrix<double> ComputeFaceDescriptor(LossMetric net, Image img, FullObjectDetection face, int numberOfJitters)
|
||||
{
|
||||
FullObjectDetection[]? faces = new[] { face };
|
||||
FullObjectDetection[]? faces = [face];
|
||||
return ComputeFaceDescriptors(net, img, faces, numberOfJitters).First();
|
||||
}
|
||||
|
||||
public static IEnumerable<Matrix<double>> ComputeFaceDescriptors(LossMetric net, Image img, IEnumerable<FullObjectDetection> faces, int numberOfJitters)
|
||||
{
|
||||
Image[]? batchImage = new[] { img };
|
||||
IEnumerable<FullObjectDetection>[]? batchFaces = new[] { faces };
|
||||
Image[]? batchImage = [img];
|
||||
IEnumerable<FullObjectDetection>[]? batchFaces = [faces];
|
||||
return BatchComputeFaceDescriptors(net, batchImage, batchFaces, numberOfJitters).First();
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ internal sealed class FaceRecognitionModelV1
|
||||
}
|
||||
|
||||
List<Array<Matrix<RgbPixel>>>? faceChipsArray = new(batchImages.Count);
|
||||
List<Matrix<RgbPixel>>? faceChips = new();
|
||||
List<Matrix<RgbPixel>>? faceChips = [];
|
||||
for (int i = 0; i < batchImages.Count; ++i)
|
||||
{
|
||||
IEnumerable<FullObjectDetection>? faces = batchFaces[i];
|
||||
@ -56,9 +56,9 @@ internal sealed class FaceRecognitionModelV1
|
||||
det.Dispose();
|
||||
}
|
||||
|
||||
List<List<Matrix<double>>>? faceDescriptors = new();
|
||||
List<List<Matrix<double>>>? faceDescriptors = [];
|
||||
for (int i = 0, count = batchImages.Count; i < count; i++)
|
||||
faceDescriptors.Add(new List<Matrix<double>>());
|
||||
faceDescriptors.Add([]);
|
||||
|
||||
if (numberOfJitters <= 1)
|
||||
{
|
||||
@ -115,7 +115,7 @@ internal sealed class FaceRecognitionModelV1
|
||||
|
||||
private static IEnumerable<Matrix<RgbPixel>> JitterImage(Matrix<RgbPixel> img, int numberOfJitters)
|
||||
{
|
||||
List<Matrix<RgbPixel>>? crops = new();
|
||||
List<Matrix<RgbPixel>>? crops = [];
|
||||
for (int i = 0; i < numberOfJitters; ++i)
|
||||
crops.Add(DlibDotNet.Dlib.JitterImage(img, _Rand));
|
||||
|
||||
|
@ -15,7 +15,7 @@ internal sealed class SimpleObjectDetector
|
||||
List<double> detectionConfidences,
|
||||
List<ulong> weightIndices)
|
||||
{
|
||||
List<Rectangle>? rectangles = new();
|
||||
List<Rectangle>? rectangles = [];
|
||||
|
||||
if (img.Mode == Mode.Greyscale)
|
||||
{
|
||||
@ -127,8 +127,8 @@ internal sealed class SimpleObjectDetector
|
||||
detector.ThrowIfDisposed();
|
||||
image.ThrowIfDisposed();
|
||||
|
||||
List<double>? detectionConfidences = new();
|
||||
List<ulong>? weightIndices = new();
|
||||
List<double>? detectionConfidences = [];
|
||||
List<ulong>? weightIndices = [];
|
||||
const double adjustThreshold = 0.0;
|
||||
|
||||
Rectangle[]? rects = RunDetectorWithUpscale1(detector,
|
||||
|
@ -71,15 +71,13 @@ public class FaceRecognition : DisposableObject
|
||||
|
||||
private static FacePoint[] Join(IEnumerable<FacePoint> facePoints1, IEnumerable<FacePoint> facePoints2)
|
||||
{
|
||||
List<FacePoint> results = new();
|
||||
results.AddRange(facePoints1);
|
||||
results.AddRange(facePoints2);
|
||||
List<FacePoint> results = [.. facePoints1, .. facePoints2];
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
private List<(FacePart, FacePoint[])> GetFaceParts(FullObjectDetection fullObjectDetection)
|
||||
{
|
||||
List<(FacePart, FacePoint[])> results = new();
|
||||
List<(FacePart, FacePoint[])> results = [];
|
||||
FacePoint[] facePoints = Enumerable.Range(0, (int)fullObjectDetection.Parts)
|
||||
.Select(index => new FacePoint(index, fullObjectDetection.GetPart((uint)index).X, fullObjectDetection.GetPart((uint)index).Y))
|
||||
.ToArray();
|
||||
@ -141,7 +139,7 @@ public class FaceRecognition : DisposableObject
|
||||
throw new NullReferenceException(nameof(image));
|
||||
image.ThrowIfDisposed();
|
||||
ThrowIfDisposed();
|
||||
List<Location> results = new();
|
||||
List<Location> results = [];
|
||||
System.Drawing.Rectangle rectangle;
|
||||
IEnumerable<MModRect> mModRects = GetMModRects(image);
|
||||
foreach (MModRect? mModRect in mModRects)
|
||||
@ -156,7 +154,7 @@ public class FaceRecognition : DisposableObject
|
||||
|
||||
private List<FullObjectDetection> GetFullObjectDetections(Image image, List<Location> locations)
|
||||
{
|
||||
List<FullObjectDetection> results = new();
|
||||
List<FullObjectDetection> results = [];
|
||||
if (_PredictorModel == PredictorModel.Custom)
|
||||
{
|
||||
if (CustomFaceLandmarkDetector is null)
|
||||
@ -182,9 +180,9 @@ public class FaceRecognition : DisposableObject
|
||||
|
||||
private List<Location> GetLocations(Image image)
|
||||
{
|
||||
List<Location> results = new();
|
||||
List<Location> results = [];
|
||||
MModRect[] mModRects = GetMModRects(image);
|
||||
if (mModRects.Any())
|
||||
if (mModRects.Length != 0)
|
||||
{
|
||||
Location location;
|
||||
System.Drawing.Rectangle rectangle;
|
||||
@ -201,7 +199,7 @@ public class FaceRecognition : DisposableObject
|
||||
|
||||
public List<(Location, FaceEncoding?, Dictionary<FacePart, FacePoint[]>?)> GetCollection(Image image, List<Location>? locations, bool includeFaceEncoding, bool includeFaceParts)
|
||||
{
|
||||
List<(Location, FaceEncoding?, Dictionary<FacePart, FacePoint[]>?)> results = new();
|
||||
List<(Location, FaceEncoding?, Dictionary<FacePart, FacePoint[]>?)> results = [];
|
||||
if (image is null)
|
||||
throw new NullReferenceException(nameof(image));
|
||||
image.ThrowIfDisposed();
|
||||
@ -210,14 +208,14 @@ public class FaceRecognition : DisposableObject
|
||||
throw new NotSupportedException("FaceRecognition.PredictorModel.Custom is not supported.");
|
||||
if (locations is null)
|
||||
locations = GetLocations(image);
|
||||
else if (!locations.Any())
|
||||
else if (locations.Count == 0)
|
||||
locations.AddRange(GetLocations(image));
|
||||
List<FullObjectDetection> fullObjectDetections = GetFullObjectDetections(image, locations);
|
||||
if (fullObjectDetections.Count != locations.Count)
|
||||
throw new Exception();
|
||||
List<(Location Location, List<FaceEncoding?> FaceEncodings, List<List<(FacePart, FacePoint[])>> FaceParts)> collection = new();
|
||||
List<(Location Location, List<FaceEncoding?> FaceEncodings, List<List<(FacePart, FacePoint[])>> FaceParts)> collection = [];
|
||||
foreach (Location location in locations)
|
||||
collection.Add(new(location, new(), new()));
|
||||
collection.Add(new(location, [], []));
|
||||
if (locations.Count != collection.Count)
|
||||
throw new Exception();
|
||||
if (!includeFaceEncoding)
|
||||
@ -239,7 +237,7 @@ public class FaceRecognition : DisposableObject
|
||||
if (!includeFaceParts)
|
||||
{
|
||||
for (int i = 0; i < collection.Count; i++)
|
||||
collection[i].FaceParts.Add(new());
|
||||
collection[i].FaceParts.Add([]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -258,11 +256,11 @@ public class FaceRecognition : DisposableObject
|
||||
{
|
||||
if (faceEncodings.Count != 1 || faceParts.Count != 1)
|
||||
continue;
|
||||
if (!faceParts[indexZero].Any())
|
||||
if (faceParts[indexZero].Count == 0)
|
||||
results.Add(new(location, faceEncodings[indexZero], null));
|
||||
else
|
||||
{
|
||||
keyValuePairs = new();
|
||||
keyValuePairs = [];
|
||||
foreach ((FacePart facePart, FacePoint[] facePoints) in faceParts[indexZero])
|
||||
keyValuePairs.Add(facePart, facePoints);
|
||||
results.Add(new(location, faceEncodings[indexZero], keyValuePairs));
|
||||
@ -412,7 +410,7 @@ public class FaceRecognition : DisposableObject
|
||||
|
||||
public static List<FaceDistance> FaceDistances(ReadOnlyCollection<FaceDistance> faceDistances, FaceDistance faceDistanceToCompare)
|
||||
{
|
||||
List<FaceDistance> results = new();
|
||||
List<FaceDistance> results = [];
|
||||
if (faceDistances is null)
|
||||
throw new NullReferenceException(nameof(faceDistances));
|
||||
if (faceDistances.Count != 0)
|
||||
|
Reference in New Issue
Block a user