After testing E_Distance.SaveGroupedFaceEncodings
This commit is contained in:
@ -41,7 +41,7 @@ public class DlibDotNet
|
||||
Person[] people;
|
||||
_AppSettings = appSettings;
|
||||
if (appSettings.MaxDegreeOfParallelism is null)
|
||||
throw new Exception($"{nameof(appSettings.MaxDegreeOfParallelism)} is null!");
|
||||
throw new ArgumentNullException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
_IsEnvironment = isEnvironment;
|
||||
_Exceptions = new List<string>();
|
||||
_Log = Serilog.Log.ForContext<DlibDotNet>();
|
||||
@ -61,21 +61,21 @@ public class DlibDotNet
|
||||
_Distance = new E_Distance(configuration);
|
||||
_FaceLandmarks = new D2_FaceLandmarks(configuration);
|
||||
if (configuration.ForceMetadataLastWriteTimeToCreationTime is null)
|
||||
throw new Exception($"{nameof(configuration.ForceMetadataLastWriteTimeToCreationTime)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.ForceMetadataLastWriteTimeToCreationTime));
|
||||
if (configuration.ForceResizeLastWriteTimeToCreationTime is null)
|
||||
throw new Exception($"{nameof(configuration.ForceResizeLastWriteTimeToCreationTime)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.ForceResizeLastWriteTimeToCreationTime));
|
||||
if (configuration.IgnoreExtensions is null)
|
||||
throw new Exception($"{nameof(configuration.IgnoreExtensions)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.OutputQuality is null)
|
||||
throw new Exception($"{nameof(configuration.OutputQuality)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.OutputQuality));
|
||||
if (configuration.OverrideForResizeImages is null)
|
||||
throw new Exception($"{nameof(configuration.OverrideForResizeImages)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.OverrideForResizeImages));
|
||||
if (configuration.PropertiesChangedForMetadata is null)
|
||||
throw new Exception($"{nameof(configuration.PropertiesChangedForMetadata)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.PropertiesChangedForMetadata));
|
||||
if (configuration.PropertiesChangedForResize is null)
|
||||
throw new Exception($"{nameof(configuration.PropertiesChangedForResize)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.PropertiesChangedForResize));
|
||||
if (configuration.Reverse is null)
|
||||
throw new Exception($"{nameof(configuration.Reverse)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.Reverse));
|
||||
_Metadata = new(configuration.ForceMetadataLastWriteTimeToCreationTime.Value, configuration.PropertiesChangedForMetadata.Value);
|
||||
if (args.Count > 0)
|
||||
argZero = Path.GetFullPath(args[0]);
|
||||
@ -88,7 +88,7 @@ public class DlibDotNet
|
||||
(Model model, PredictorModel predictorModel, ModelParameter modelParameter) = GetModel(configuration);
|
||||
_Faces = new D_Face(configuration, argZero, model, modelParameter, predictorModel);
|
||||
if (configuration.SkipSearch is null)
|
||||
throw new Exception($"{nameof(configuration.SkipSearch)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.SkipSearch));
|
||||
if (!_ArgZeroIsConfigurationRootDirectory)
|
||||
people = Array.Empty<Person>();
|
||||
else
|
||||
@ -134,7 +134,7 @@ public class DlibDotNet
|
||||
{
|
||||
long result;
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
double delta = new TimeSpan(DateTime.Now.Ticks - ticks).TotalMilliseconds;
|
||||
_Log.Debug($"{methodName} took {Math.Floor(delta)} millisecond(s)");
|
||||
result = DateTime.Now.Ticks;
|
||||
@ -188,7 +188,7 @@ public class DlibDotNet
|
||||
private void Verify(Models.Configuration configuration)
|
||||
{
|
||||
if (!configuration.OutputResolutions.Any() || string.IsNullOrEmpty(configuration.OutputResolutions[0]) || !configuration.ValidResolutions.Contains(configuration.OutputResolutions[0]))
|
||||
throw new Exception($"{nameof(configuration.OutputResolutions)} must be a valid outputResolution!");
|
||||
throw new ArgumentNullException(nameof(configuration.OutputResolutions), "must be a valid outputResolution!");
|
||||
if ((from l in configuration.OutputResolutions where !configuration.ValidResolutions.Contains(l) select false).Any())
|
||||
throw new Exception($"One or more {nameof(configuration.OutputResolutions)} are not in the ValidResolutions list!");
|
||||
if ((from l in configuration.LoadOrCreateThenSaveDirectoryDistanceResultsForOutputResolutions where !configuration.ValidResolutions.Contains(l) select false).Any())
|
||||
@ -202,79 +202,81 @@ public class DlibDotNet
|
||||
if ((from l in configuration.SaveFaceLandmarkForOutputResolutions where !configuration.ValidResolutions.Contains(l) select false).Any())
|
||||
throw new Exception($"One or more {nameof(configuration.SaveFaceLandmarkForOutputResolutions)} are not in the ValidResolutions list!");
|
||||
if (configuration.CheckJsonForDistanceResults is null)
|
||||
throw new Exception($"{nameof(configuration.CheckJsonForDistanceResults)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.CheckJsonForDistanceResults));
|
||||
if (configuration.CrossDirectoryMaxItemsInDistanceCollection is null)
|
||||
throw new Exception($"{nameof(configuration.CrossDirectoryMaxItemsInDistanceCollection)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.CrossDirectoryMaxItemsInDistanceCollection));
|
||||
if (configuration.DistanceFactor is null)
|
||||
throw new Exception($"{nameof(configuration.DistanceFactor)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.DistanceFactor));
|
||||
if (configuration.ForceMetadataLastWriteTimeToCreationTime is null)
|
||||
throw new Exception($"{nameof(configuration.ForceMetadataLastWriteTimeToCreationTime)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.ForceMetadataLastWriteTimeToCreationTime));
|
||||
if (configuration.ForceResizeLastWriteTimeToCreationTime is null)
|
||||
throw new Exception($"{nameof(configuration.ForceResizeLastWriteTimeToCreationTime)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.ForceResizeLastWriteTimeToCreationTime));
|
||||
if (configuration.IgnoreExtensions is null)
|
||||
throw new Exception($"{nameof(configuration.IgnoreExtensions)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.IgnoreRelativePaths is null)
|
||||
throw new Exception($"{nameof(configuration.IgnoreRelativePaths)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.IgnoreRelativePaths));
|
||||
if (configuration.LoadOrCreateThenSaveIndex is null)
|
||||
throw new Exception($"{nameof(configuration.LoadOrCreateThenSaveIndex)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.LoadOrCreateThenSaveIndex));
|
||||
if (configuration.LocationConfidenceFactor is null)
|
||||
throw new Exception($"{nameof(configuration.LocationConfidenceFactor)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.LocationConfidenceFactor));
|
||||
if (configuration.MappedMaxIndex is null)
|
||||
throw new Exception($"{nameof(configuration.MappedMaxIndex)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.MappedMaxIndex));
|
||||
if (configuration.MappedMaxIndex.HasValue && configuration.LoadOrCreateThenSaveIndex.Value && !_IsEnvironment.DebuggerWasAttachedDuringConstructor)
|
||||
throw new Exception($"{nameof(configuration.MappedMaxIndex)} only allowed when debugger is attached!");
|
||||
throw new ArgumentNullException(nameof(configuration.MappedMaxIndex));
|
||||
if (configuration.MaxItemsInDistanceCollection is null)
|
||||
throw new Exception($"{nameof(configuration.MaxItemsInDistanceCollection)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.MaxItemsInDistanceCollection));
|
||||
if (configuration.MixedYearRelativePaths is null)
|
||||
throw new Exception($"{nameof(configuration.MixedYearRelativePaths)} must be set!");
|
||||
if (configuration.NumJitters is null)
|
||||
throw new Exception($"{nameof(configuration.NumJitters)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.MixedYearRelativePaths));
|
||||
if (configuration.NumberOfJitters is null)
|
||||
throw new ArgumentNullException(nameof(configuration.NumberOfJitters));
|
||||
if (configuration.NumberOfTimesToUpsample is null)
|
||||
throw new ArgumentNullException(nameof(configuration.NumberOfTimesToUpsample));
|
||||
if (configuration.OutputQuality is null)
|
||||
throw new Exception($"{nameof(configuration.OutputQuality)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.OutputQuality));
|
||||
if (configuration.OutputResolutions is null)
|
||||
throw new Exception($"{nameof(configuration.OutputResolutions)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.OutputResolutions));
|
||||
if (configuration.OverrideForFaceImages is null)
|
||||
throw new Exception($"{nameof(configuration.OverrideForFaceImages)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.OverrideForFaceImages));
|
||||
if (configuration.OverrideForFaceLandmarkImages is null)
|
||||
throw new Exception($"{nameof(configuration.OverrideForFaceLandmarkImages)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.OverrideForFaceLandmarkImages));
|
||||
if (configuration.OverrideForResizeImages is null)
|
||||
throw new Exception($"{nameof(configuration.OverrideForResizeImages)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.OverrideForResizeImages));
|
||||
if (configuration.PaddingLoops is null)
|
||||
throw new Exception($"{nameof(configuration.PaddingLoops)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.PaddingLoops));
|
||||
if (configuration.PropertiesChangedForDistance is null)
|
||||
throw new Exception($"{nameof(configuration.PropertiesChangedForDistance)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.PropertiesChangedForDistance));
|
||||
if (configuration.PropertiesChangedForFaces is null)
|
||||
throw new Exception($"{nameof(configuration.PropertiesChangedForFaces)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.PropertiesChangedForFaces));
|
||||
if (configuration.PropertiesChangedForIndex is null)
|
||||
throw new Exception($"{nameof(configuration.PropertiesChangedForIndex)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.PropertiesChangedForIndex));
|
||||
if (configuration.PropertiesChangedForMetadata is null)
|
||||
throw new Exception($"{nameof(configuration.PropertiesChangedForMetadata)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.PropertiesChangedForMetadata));
|
||||
if (configuration.PropertiesChangedForResize is null)
|
||||
throw new Exception($"{nameof(configuration.PropertiesChangedForResize)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.PropertiesChangedForResize));
|
||||
if (configuration.Reverse is null)
|
||||
throw new Exception($"{nameof(configuration.Reverse)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.Reverse));
|
||||
if (configuration.SaveFaceLandmarkForOutputResolutions is null)
|
||||
throw new Exception($"{nameof(configuration.SaveFaceLandmarkForOutputResolutions)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.SaveFaceLandmarkForOutputResolutions));
|
||||
if (configuration.SaveFullYearOfRandomFiles is null)
|
||||
throw new Exception($"{nameof(configuration.SaveFullYearOfRandomFiles)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.SaveFullYearOfRandomFiles));
|
||||
if (configuration.SaveResizedSubfiles is null)
|
||||
throw new Exception($"{nameof(configuration.SaveResizedSubfiles)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.SaveResizedSubfiles));
|
||||
if (configuration.SkipSearch is null)
|
||||
throw new Exception($"{nameof(configuration.SkipSearch)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.SkipSearch));
|
||||
if (configuration.TestDistanceResults is null)
|
||||
throw new Exception($"{nameof(configuration.TestDistanceResults)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.TestDistanceResults));
|
||||
if (configuration.ValidResolutions is null)
|
||||
throw new Exception($"{nameof(configuration.ValidResolutions)} must be set!");
|
||||
throw new ArgumentNullException(nameof(configuration.ValidResolutions));
|
||||
if (string.IsNullOrEmpty(configuration.ModelDirectory) || !Directory.Exists(configuration.ModelDirectory))
|
||||
throw new Exception($"{nameof(configuration.ModelDirectory)} must have a value and exits!");
|
||||
throw new ArgumentNullException(nameof(configuration.ModelDirectory));
|
||||
if (string.IsNullOrEmpty(configuration.ModelName))
|
||||
throw new Exception($"{nameof(configuration.ModelName)} must have a value!");
|
||||
throw new ArgumentNullException(nameof(configuration.ModelName));
|
||||
if (string.IsNullOrEmpty(configuration.OutputExtension))
|
||||
throw new Exception($"{nameof(configuration.OutputExtension)} must have a value!");
|
||||
throw new ArgumentNullException(nameof(configuration.OutputExtension));
|
||||
if (string.IsNullOrEmpty(configuration.PredictorModelName))
|
||||
throw new Exception($"{nameof(configuration.PredictorModelName)} must have a value!");
|
||||
throw new ArgumentNullException(nameof(configuration.PredictorModelName));
|
||||
if (configuration.DistanceFactor.Value + configuration.LocationConfidenceFactor.Value != 10)
|
||||
throw new Exception($"{nameof(configuration.DistanceFactor)} and {nameof(configuration.LocationConfidenceFactor)} must add up to 10!");
|
||||
throw new ArgumentNullException(nameof(configuration.DistanceFactor));
|
||||
}
|
||||
|
||||
private void VerifyExtra(List<string> args, Property.Models.Configuration propertyConfiguration, Models.Configuration configuration)
|
||||
@ -306,15 +308,15 @@ public class DlibDotNet
|
||||
private void FullParallelForWork(PropertyLogic propertyLogic, object @lock, string outputResolution, List<Tuple<string, DateTime>> sourceDirectoryChanges, List<FileInfo?> propertyFileInfoCollection, List<A_Property> propertyCollection, List<List<KeyValuePair<string, string>>> metadataCollections, List<Dictionary<string, int[]>> resizeKeyValuePairs, List<List<D_Face>> imageFaceCollections, string sourceDirectory, int index, PropertyHolder propertyHolder)
|
||||
{
|
||||
if (propertyHolder.ImageFileInfo is null)
|
||||
throw new Exception($"{nameof(propertyHolder.ImageFileInfo)} is null!");
|
||||
throw new ArgumentNullException(nameof(propertyHolder.ImageFileInfo));
|
||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||
throw new Exception($"{nameof(_AppSettings.MaxDegreeOfParallelism)} is null!");
|
||||
throw new ArgumentNullException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||
if (_Configuration.SaveResizedSubfiles is null)
|
||||
throw new Exception($"{nameof(_Configuration.SaveResizedSubfiles)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.SaveResizedSubfiles));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
if (_Configuration.PropertyConfiguration.WriteBitmapDataBytes is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration.WriteBitmapDataBytes)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration.WriteBitmapDataBytes));
|
||||
A_Property property;
|
||||
List<D_Face> faceCollection;
|
||||
string original = "Original";
|
||||
@ -395,9 +397,9 @@ public class DlibDotNet
|
||||
{
|
||||
int result = 0;
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||
throw new Exception($"{nameof(AppSettings.MaxDegreeOfParallelism)} is null!");
|
||||
throw new ArgumentNullException(nameof(AppSettings.MaxDegreeOfParallelism));
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = _AppSettings.MaxDegreeOfParallelism.Value };
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
if (faceCollections.Count != filteredPropertyHolderCollection.Length || metadataCollection.Count != filteredPropertyHolderCollection.Length || resizeKeyValuePairs.Count != filteredPropertyHolderCollection.Length || propertyCollection.Count != filteredPropertyHolderCollection.Length)
|
||||
@ -460,7 +462,7 @@ public class DlibDotNet
|
||||
if (metadataIdLines.Any())
|
||||
{
|
||||
text = string.Join(Environment.NewLine, from l in metadataIdLines orderby l.Id select l.Line);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, text, compareBeforeWrite: true);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, text, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -472,19 +474,18 @@ public class DlibDotNet
|
||||
private void WriteGroup(Property.Models.Configuration configuration, PropertyLogic propertyLogic, List<A_Property> propertyCollection, List<List<KeyValuePair<string, string>>> metadataCollection, List<List<D_Face>> faceCollections, List<Dictionary<string, int[]>> resizeKeyValuePairs, string sourceDirectory, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection)
|
||||
{
|
||||
if (_Configuration.PropertiesChangedForMetadata is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertiesChangedForMetadata)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertiesChangedForMetadata));
|
||||
if (configuration.PropertiesChangedForProperty is null)
|
||||
throw new Exception($"{nameof(configuration.PropertiesChangedForProperty)} is null!");
|
||||
throw new ArgumentNullException(nameof(configuration.PropertiesChangedForProperty));
|
||||
if (_Configuration.PropertiesChangedForResize is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertiesChangedForResize)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertiesChangedForResize));
|
||||
if (_Configuration.PropertiesChangedForFaces is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertiesChangedForFaces)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertiesChangedForFaces));
|
||||
string key;
|
||||
string json;
|
||||
string checkFile;
|
||||
PropertyHolder propertyHolder;
|
||||
int sourceDirectoryLength = sourceDirectory.Length;
|
||||
int rootDirectoryLength = configuration.RootDirectory.Length;
|
||||
_FilePropertiesKeyValuePairs.Add(sourceDirectory, new List<Tuple<string, A_Property>>());
|
||||
JsonSerializerOptions writeIndentedJsonSerializerOptions = new() { WriteIndented = false };
|
||||
if (!(from l in propertyCollection where l?.Width is null select true).Any())
|
||||
@ -511,16 +512,6 @@ public class DlibDotNet
|
||||
resizeKeyValuePairsCollections.Add(new KeyValuePair<string, Dictionary<string, int[]>>(key, resizeKeyValuePairs[i]));
|
||||
metadataCollectionKeyValuePairs.Add(new KeyValuePair<string, List<KeyValuePair<string, string>>>(key, metadataCollection[i]));
|
||||
}
|
||||
if (_Metadata.AngleBracketCollection.Any())
|
||||
{
|
||||
checkDirectory = Property.Models.Stateless.IPath.GetDirectory(_Metadata.AngleBracketCollection[0], level, "[{}]");
|
||||
checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
File.Move(checkFile, Path.Combine(checkDirectory, fileName));
|
||||
checkFile = Path.Combine(checkDirectory, fileName);
|
||||
json = JsonSerializer.Serialize(metadataCollectionKeyValuePairs, writeIndentedJsonSerializerOptions);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, compareBeforeWrite: true);
|
||||
}
|
||||
if (propertyLogic.AngleBracketCollection.Any())
|
||||
{
|
||||
checkDirectory = Property.Models.Stateless.IPath.GetDirectory(propertyLogic.AngleBracketCollection[0], level, "[{}]");
|
||||
@ -529,7 +520,17 @@ public class DlibDotNet
|
||||
File.Move(checkFile, Path.Combine(checkDirectory, fileName));
|
||||
checkFile = Path.Combine(checkDirectory, fileName);
|
||||
json = JsonSerializer.Serialize(propertyCollectionKeyValuePairs, writeIndentedJsonSerializerOptions);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, compareBeforeWrite: true);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
if (_Metadata.AngleBracketCollection.Any())
|
||||
{
|
||||
checkDirectory = Property.Models.Stateless.IPath.GetDirectory(_Metadata.AngleBracketCollection[0], level, "[{}]");
|
||||
checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
File.Move(checkFile, Path.Combine(checkDirectory, fileName));
|
||||
checkFile = Path.Combine(checkDirectory, fileName);
|
||||
json = JsonSerializer.Serialize(metadataCollectionKeyValuePairs, writeIndentedJsonSerializerOptions);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
if (_Resize.AngleBracketCollection.Any())
|
||||
{
|
||||
@ -539,7 +540,7 @@ public class DlibDotNet
|
||||
File.Move(checkFile, Path.Combine(checkDirectory, fileName));
|
||||
checkFile = Path.Combine(checkDirectory, fileName);
|
||||
json = JsonSerializer.Serialize(resizeKeyValuePairsCollections, writeIndentedJsonSerializerOptions);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, compareBeforeWrite: true);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
if (_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution) && _Faces.AngleBracketCollection.Any())
|
||||
{
|
||||
@ -549,7 +550,7 @@ public class DlibDotNet
|
||||
File.Move(checkFile, Path.Combine(checkDirectory, fileName));
|
||||
checkFile = Path.Combine(checkDirectory, fileName);
|
||||
json = JsonSerializer.Serialize(faceCollectionsKeyValuePairs, writeIndentedJsonSerializerOptions);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, compareBeforeWrite: true);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -557,9 +558,9 @@ public class DlibDotNet
|
||||
private void FullDoWork(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string argZero, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, List<PropertyHolder[]> propertyHolderCollections)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||
throw new Exception($"{nameof(_AppSettings.MaxDegreeOfParallelism)} is null!");
|
||||
throw new ArgumentNullException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||
int g;
|
||||
int r;
|
||||
int exceptionCount;
|
||||
@ -677,11 +678,11 @@ public class DlibDotNet
|
||||
{
|
||||
if (outputResolution == _Configuration.OutputResolutions[0] || _Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution))
|
||||
{
|
||||
PropertyHolder.AddToNamed(propertyLogic, filteredPropertyHolderCollection);
|
||||
for (int i = 0; i < faceCollections.Count; i++)
|
||||
PropertyHolder.AddToFaces(filteredPropertyHolderCollection, (from l in faceCollections[i] select (object)l).ToArray());
|
||||
filteredPropertyHolderCollection[i].Faces.AddRange(from l in faceCollections[i] select l);
|
||||
PropertyHolder.AddToNamed(propertyLogic, filteredPropertyHolderCollection);
|
||||
if (_Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution))
|
||||
D_Face.SaveShortcuts(configuration, model, predictorModel, _Configuration.JuliePhares, peopleCollection, propertyLogic, outputResolution, filteredPropertyHolderCollection, faceCollections);
|
||||
D_Face.SaveShortcuts(configuration, model, predictorModel, _Configuration.JuliePhares, ticks, peopleCollection, propertyLogic, outputResolution, filteredPropertyHolderCollection);
|
||||
}
|
||||
}
|
||||
if (exceptionCount == 0 && _Configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions.Contains(outputResolution))
|
||||
@ -707,7 +708,7 @@ public class DlibDotNet
|
||||
{
|
||||
propertyLogic.SaveAllCollection();
|
||||
if (propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.Any())
|
||||
E_Distance.SaveGroupedFaceEncodings(configuration, model, predictorModel, argZero, peopleCollection, outputResolution, propertyHolderCollections);
|
||||
E_Distance.SaveGroupedFaceEncodings(configuration, model, predictorModel, argZero, ticks, peopleCollection, outputResolution, propertyHolderCollections);
|
||||
if (!_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Any())
|
||||
break;
|
||||
if (_Exceptions.Count == 0)
|
||||
@ -731,9 +732,9 @@ public class DlibDotNet
|
||||
{
|
||||
PropertyLogic result;
|
||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||
throw new Exception($"{nameof(_AppSettings.MaxDegreeOfParallelism)} is null!");
|
||||
throw new ArgumentNullException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
@ -24,7 +24,8 @@ public class Configuration
|
||||
[Display(Name = "Mixed Year Relative Paths"), Required] public string[] MixedYearRelativePaths { get; set; }
|
||||
[Display(Name = "Model Directory"), Required] public string ModelDirectory { get; set; }
|
||||
[Display(Name = "Model Name"), Required] public string ModelName { get; set; }
|
||||
[Display(Name = "Num Jitters"), Required] public int? NumJitters { get; set; }
|
||||
[Display(Name = "Number Jitters"), Required] public int? NumberOfJitters { get; set; }
|
||||
[Display(Name = "Number of Times To Up Sample"), Required] public int? NumberOfTimesToUpsample { get; set; }
|
||||
[Display(Name = "Output Extension"), Required] public string OutputExtension { get; set; }
|
||||
[Display(Name = "Output Quality"), Required] public int? OutputQuality { get; set; }
|
||||
[Display(Name = "Output Resolutions"), Required] public string[] OutputResolutions { get; set; }
|
||||
@ -68,7 +69,8 @@ public class Configuration
|
||||
MixedYearRelativePaths = Array.Empty<string>();
|
||||
ModelDirectory = string.Empty;
|
||||
ModelName = string.Empty;
|
||||
NumJitters = null;
|
||||
NumberOfJitters = null;
|
||||
NumberOfTimesToUpsample = null;
|
||||
OutputExtension = string.Empty;
|
||||
OutputQuality = null;
|
||||
OutputResolutions = Array.Empty<string>();
|
||||
|
@ -24,7 +24,8 @@ public class Configuration
|
||||
protected readonly string[] _MixedYearRelativePaths;
|
||||
protected readonly string _ModelDirectory;
|
||||
protected readonly string _ModelName;
|
||||
protected readonly int? _NumJitters;
|
||||
protected readonly int? _NumberOfJitters;
|
||||
protected readonly int? _NumberOfTimesToUpsample;
|
||||
protected readonly string _OutputExtension;
|
||||
protected readonly int? _OutputQuality;
|
||||
protected readonly string[] _OutputResolutions;
|
||||
@ -65,7 +66,8 @@ public class Configuration
|
||||
public string[] MixedYearRelativePaths => _MixedYearRelativePaths;
|
||||
public string ModelDirectory => _ModelDirectory;
|
||||
public string ModelName => _ModelName;
|
||||
public int? NumJitters => _NumJitters;
|
||||
public int? NumberOfJitters => _NumberOfJitters;
|
||||
public int? NumberOfTimesToUpsample => _NumberOfTimesToUpsample;
|
||||
public string OutputExtension => _OutputExtension;
|
||||
public int? OutputQuality => _OutputQuality;
|
||||
public string[] OutputResolutions => _OutputResolutions;
|
||||
@ -90,7 +92,7 @@ public class Configuration
|
||||
public string[] ValidResolutions => _ValidResolutions;
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(bool? checkJsonForDistanceResults, int? crossDirectoryMaxItemsInDistanceCollection, int? distanceFactor, bool? forceMetadataLastWriteTimeToCreationTime, bool? forceResizeLastWriteTimeToCreationTime, string[] ignoreExtensions, string[] ignoreRelativePaths, string[] juliePhares, string[] loadOrCreateThenSaveDirectoryDistanceResultsForOutputResolutions, string[] loadOrCreateThenSaveDistanceResultsForOutputResolutions, string[] loadOrCreateThenSaveImageFacesResultsForOutputResolutions, bool? loadOrCreateThenSaveIndex, int? locationConfidenceFactor, int? mappedMaxIndex, int? maxItemsInDistanceCollection, string[] mixedYearRelativePaths, string modelDirectory, string modelName, int? numJitters, string outputExtension, int? outputQuality, string[] outputResolutions, bool? overrideForFaceImages, bool? overrideForFaceLandmarkImages, bool? overrideForResizeImages, int? paddingLoops, string predictorModelName, bool? propertiesChangedForDistance, bool? propertiesChangedForFaces, bool? propertiesChangedForIndex, bool? propertiesChangedForMetadata, bool? propertiesChangedForResize, Property.Models.Configuration? propertyConfiguration, bool? reverse, string[] saveFaceLandmarkForOutputResolutions, bool? saveFullYearOfRandomFiles, bool? saveResizedSubfiles, string[] saveShortcutsForOutputResolutions, bool? skipSearch, bool? testDistanceResults, string[] validResolutions)
|
||||
public Configuration(bool? checkJsonForDistanceResults, int? crossDirectoryMaxItemsInDistanceCollection, int? distanceFactor, bool? forceMetadataLastWriteTimeToCreationTime, bool? forceResizeLastWriteTimeToCreationTime, string[] ignoreExtensions, string[] ignoreRelativePaths, string[] juliePhares, string[] loadOrCreateThenSaveDirectoryDistanceResultsForOutputResolutions, string[] loadOrCreateThenSaveDistanceResultsForOutputResolutions, string[] loadOrCreateThenSaveImageFacesResultsForOutputResolutions, bool? loadOrCreateThenSaveIndex, int? locationConfidenceFactor, int? mappedMaxIndex, int? maxItemsInDistanceCollection, string[] mixedYearRelativePaths, string modelDirectory, string modelName, int? numberOfJitters, int? numberOfTimesToUpsample, string outputExtension, int? outputQuality, string[] outputResolutions, bool? overrideForFaceImages, bool? overrideForFaceLandmarkImages, bool? overrideForResizeImages, int? paddingLoops, string predictorModelName, bool? propertiesChangedForDistance, bool? propertiesChangedForFaces, bool? propertiesChangedForIndex, bool? propertiesChangedForMetadata, bool? propertiesChangedForResize, Property.Models.Configuration? propertyConfiguration, bool? reverse, string[] saveFaceLandmarkForOutputResolutions, bool? saveFullYearOfRandomFiles, bool? saveResizedSubfiles, string[] saveShortcutsForOutputResolutions, bool? skipSearch, bool? testDistanceResults, string[] validResolutions)
|
||||
{
|
||||
_CheckJsonForDistanceResults = checkJsonForDistanceResults;
|
||||
_CrossDirectoryMaxItemsInDistanceCollection = crossDirectoryMaxItemsInDistanceCollection;
|
||||
@ -110,7 +112,8 @@ public class Configuration
|
||||
_MixedYearRelativePaths = mixedYearRelativePaths;
|
||||
_ModelDirectory = modelDirectory;
|
||||
_ModelName = modelName;
|
||||
_NumJitters = numJitters;
|
||||
_NumberOfJitters = numberOfJitters;
|
||||
_NumberOfTimesToUpsample = numberOfTimesToUpsample;
|
||||
_OutputExtension = outputExtension;
|
||||
_OutputQuality = outputQuality;
|
||||
_OutputResolutions = outputResolutions;
|
||||
|
@ -56,7 +56,7 @@ internal class A2_People
|
||||
_ = Directory.CreateDirectory(directoryFullName);
|
||||
jsonFile = Path.Combine(directoryFullName, $"{segments[1]}.json");
|
||||
json = JsonSerializer.Serialize(keyValuePair.Value, _WriteIndentedJsonSerializerOptions);
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, compareBeforeWrite: true))
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -65,7 +65,7 @@ internal class A2_People
|
||||
{
|
||||
Person[] results;
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
string rootDirectory = _Configuration.PropertyConfiguration.RootDirectory;
|
||||
string peopleRootDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A2_People));
|
||||
string? rootResultsDirectory = Path.GetDirectoryName(Path.GetDirectoryName(peopleRootDirectory));
|
||||
|
@ -116,8 +116,10 @@ internal class D2_FaceLandmarks
|
||||
string parentCheck;
|
||||
const int pointSize = 2;
|
||||
FileInfo rotatedFileInfo;
|
||||
DateTime? dateTime = null;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
List<string[]> imageFiles = new();
|
||||
bool updateDateWhenMatches = false;
|
||||
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), propertyHolder.ImageFileNameWithoutExtension);
|
||||
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize), nameof(D_Face) };
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
@ -155,6 +157,11 @@ internal class D2_FaceLandmarks
|
||||
check = true;
|
||||
else if (dateTimes.Any() && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
check = true;
|
||||
if (check && !updateDateWhenMatches)
|
||||
{
|
||||
updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
}
|
||||
}
|
||||
if (check)
|
||||
SaveFaceLandmarkImages(faceCollections, imageFiles, pointSize, propertyHolder.ResizedFileInfo);
|
||||
|
@ -233,10 +233,12 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
if (!faceCollection[i].Populated || faceCollection[i]?.Location is null)
|
||||
continue;
|
||||
location = new Location(faceCollection[i].Location.Confidence,
|
||||
faceCollection[i].Location.Bottom,
|
||||
faceCollection[i].Location.Left,
|
||||
faceCollection[i].Location.Right,
|
||||
faceCollection[i].Location.Top);
|
||||
faceCollection[i].Location.Bottom,
|
||||
faceCollection[i].Location.Left,
|
||||
faceCollection[i].Location.Right,
|
||||
faceCollection[i].Location.Top,
|
||||
source.Width,
|
||||
source.Height);
|
||||
width = location.Right - location.Left;
|
||||
height = location.Bottom - location.Top;
|
||||
rectangle = new Rectangle(location.Left, location.Top, width, height);
|
||||
@ -254,10 +256,11 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
List<D_Face> results = new();
|
||||
if (_Configuration.PaddingLoops is null)
|
||||
throw new Exception();
|
||||
if (_Configuration.NumJitters is null)
|
||||
throw new Exception();
|
||||
if (_Configuration.NumberOfJitters is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.NumberOfJitters));
|
||||
if (_Configuration.NumberOfTimesToUpsample is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.NumberOfTimesToUpsample));
|
||||
List<Location> locations;
|
||||
const int numberOfTimesToUpSample = 1;
|
||||
FaceRecognitionDotNet.Image? unknownImage = null;
|
||||
if (resizedFileInfo.Exists)
|
||||
{
|
||||
@ -270,7 +273,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
else
|
||||
{
|
||||
FaceRecognition faceRecognition = FaceRecognition.Create(_ModelParameter);
|
||||
locations = faceRecognition.FaceLocations(unknownImage, numberOfTimesToUpSample, _Model);
|
||||
locations = faceRecognition.FaceLocations(_Model, unknownImage, _Configuration.NumberOfTimesToUpsample.Value, sortByPixelPercentage: true);
|
||||
if (!locations.Any())
|
||||
results.Add(new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, propertyHolder.RelativePath, i: null, location: null));
|
||||
else
|
||||
@ -279,10 +282,10 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
int width;
|
||||
int height;
|
||||
int padding;
|
||||
int leftEyeX;
|
||||
int leftEyeY;
|
||||
int rightEyeX;
|
||||
int rightEyeY;
|
||||
int? leftEyeX;
|
||||
int? leftEyeY;
|
||||
int? rightEyeX;
|
||||
int? rightEyeY;
|
||||
Bitmap rotated;
|
||||
string faceFile;
|
||||
Location location;
|
||||
@ -291,12 +294,11 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
D_Face? face = null;
|
||||
Rectangle rectangle;
|
||||
double[] rawEncoding;
|
||||
IEnumerable<FacePoint> facePoints;
|
||||
Shared.Models.FaceEncoding faceEncoding;
|
||||
FaceRecognitionDotNet.Image? knownImage;
|
||||
FaceRecognitionDotNet.Image? rotatedImage;
|
||||
List<(FacePart, FacePoint[])[]> facesLandmarks;
|
||||
List<FaceRecognitionDotNet.FaceEncoding> faceEncodings;
|
||||
List<Dictionary<FacePart, IEnumerable<FacePoint>>> faceLandmarks;
|
||||
using Bitmap source = unknownImage.ToBitmap();
|
||||
padding = (int)((source.Width + source.Height) / 2 * .01);
|
||||
for (int i = 0; i < locations.Count; i++)
|
||||
@ -304,16 +306,22 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
for (int p = 0; p <= _Configuration.PaddingLoops.Value; p++)
|
||||
{
|
||||
location = new(locations[i].Confidence,
|
||||
locations[i].Bottom + (padding * p),
|
||||
locations[i].Left - (padding * p),
|
||||
locations[i].Right + (padding * p),
|
||||
locations[i].Top - (padding * p));
|
||||
face = new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, propertyHolder.RelativePath, i, location);
|
||||
locations[i].Bottom + (padding * p),
|
||||
locations[i].Left - (padding * p),
|
||||
locations[i].Right + (padding * p),
|
||||
locations[i].Top - (padding * p),
|
||||
source.Width,
|
||||
source.Height);
|
||||
face = new(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, propertyHolder.RelativePath, i, location);
|
||||
width = location.Right - location.Left;
|
||||
height = location.Bottom - location.Top;
|
||||
rectangle = new Rectangle(location.Left, location.Top, width, height);
|
||||
using (preRotated = new Bitmap(width, height))
|
||||
{
|
||||
leftEyeX = null;
|
||||
leftEyeY = null;
|
||||
rightEyeX = null;
|
||||
rightEyeY = null;
|
||||
using (graphics = Graphics.FromImage(preRotated))
|
||||
graphics.DrawImage(source, new Rectangle(0, 0, width, height), rectangle, GraphicsUnit.Pixel);
|
||||
// source.Save(Path.Combine(_Configuration.RootDirectory, "source.jpg"));
|
||||
@ -321,32 +329,40 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
using (knownImage = FaceRecognition.LoadImage(preRotated))
|
||||
{
|
||||
if (knownImage is null || knownImage.IsDisposed)
|
||||
throw new Exception($"{nameof(knownImage)} is null");
|
||||
faceLandmarks = faceRecognition.FaceLandmark(knownImage, faceLocations: null, _PredictorModel, _Model);
|
||||
throw new ArgumentNullException(nameof(knownImage));
|
||||
facesLandmarks = faceRecognition.GetFaceLandmarkCollection(knownImage, _Configuration.NumberOfTimesToUpsample.Value, faceLocations: null, _PredictorModel, _Model);
|
||||
}
|
||||
if (faceLandmarks.Count == 0 && p < _Configuration.PaddingLoops.Value)
|
||||
if (facesLandmarks.Count == 0 && p < _Configuration.PaddingLoops.Value)
|
||||
continue;
|
||||
else if (faceLandmarks.Count != 1)
|
||||
else if (facesLandmarks.Count != 1)
|
||||
continue;
|
||||
foreach (KeyValuePair<FacePart, IEnumerable<FacePoint>> keyValuePair in faceLandmarks[0])
|
||||
face.FaceLandmarks.Add(keyValuePair.Key.ToString(), keyValuePair.Value.ToArray());
|
||||
if (!faceLandmarks[0].ContainsKey(FacePart.LeftEye) || !faceLandmarks[0].ContainsKey(FacePart.RightEye))
|
||||
foreach ((FacePart facePart, FacePoint[] facePoints) in facesLandmarks[0])
|
||||
{
|
||||
face.FaceLandmarks.Add(facePart.ToString(), facePoints);
|
||||
if (facePart is not FacePart.LeftEye and not FacePart.RightEye)
|
||||
continue;
|
||||
if (facePart is FacePart.LeftEye)
|
||||
{
|
||||
leftEyeX = (int)(from l in facePoints select l.X).Average();
|
||||
leftEyeY = (int)(from l in facePoints select l.Y).Average();
|
||||
}
|
||||
if (facePart is FacePart.RightEye)
|
||||
{
|
||||
rightEyeX = (int)(from l in facePoints select l.X).Average();
|
||||
rightEyeY = (int)(from l in facePoints select l.Y).Average();
|
||||
}
|
||||
}
|
||||
if (rightEyeX is null || leftEyeX is null || rightEyeY is null || leftEyeY is null)
|
||||
continue;
|
||||
facePoints = faceLandmarks[0][FacePart.LeftEye];
|
||||
leftEyeX = (int)(from l in facePoints select l.X).Average();
|
||||
leftEyeY = (int)(from l in facePoints select l.Y).Average();
|
||||
facePoints = faceLandmarks[0][FacePart.RightEye];
|
||||
rightEyeX = (int)(from l in facePoints select l.X).Average();
|
||||
rightEyeY = (int)(from l in facePoints select l.Y).Average();
|
||||
α = Shared.Models.Stateless.Methods.IFace.Getα(rightEyeX, leftEyeX, rightEyeY, leftEyeY);
|
||||
α = Shared.Models.Stateless.Methods.IFace.Getα(rightEyeX.Value, leftEyeX.Value, rightEyeY.Value, leftEyeY.Value);
|
||||
using (rotated = RotateBitmap(preRotated, (float)α.Value))
|
||||
{
|
||||
// rotated.Save(Path.Combine(_Configuration.RootDirectory, $"{p} - rotated.jpg"));
|
||||
using (rotatedImage = FaceRecognition.LoadImage(rotated))
|
||||
{
|
||||
if (rotatedImage is null || rotatedImage.IsDisposed)
|
||||
throw new Exception($"{nameof(rotatedImage)} is null");
|
||||
faceEncodings = faceRecognition.FaceEncodings(rotatedImage, knownFaceLocation: null, _Configuration.NumJitters.Value, _PredictorModel, _Model);
|
||||
throw new ArgumentNullException(nameof(rotatedImage));
|
||||
faceEncodings = faceRecognition.FaceEncodings(rotatedImage, _Configuration.NumberOfTimesToUpsample.Value, knownFaceLocation: null, _Configuration.NumberOfJitters.Value, _PredictorModel, _Model);
|
||||
}
|
||||
if (faceEncodings.Count == 0 && p < _Configuration.PaddingLoops.Value)
|
||||
continue;
|
||||
@ -366,10 +382,12 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
if (face is null || !face.Populated)
|
||||
{
|
||||
location = new(locations[i].Confidence,
|
||||
locations[i].Bottom,
|
||||
locations[i].Left,
|
||||
locations[i].Right,
|
||||
locations[i].Top);
|
||||
locations[i].Bottom,
|
||||
locations[i].Left,
|
||||
locations[i].Right,
|
||||
locations[i].Top,
|
||||
source.Width,
|
||||
source.Height);
|
||||
face = new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, propertyHolder.RelativePath, i, location);
|
||||
results.Add(face);
|
||||
}
|
||||
@ -427,7 +445,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
{
|
||||
results = JsonSerializer.Deserialize<List<D_Face>>(json);
|
||||
if (results is null)
|
||||
throw new Exception($"{nameof(results)} is null");
|
||||
throw new ArgumentNullException(nameof(results));
|
||||
for (int i = 0; i < results.Count; i++)
|
||||
{
|
||||
face = results[i];
|
||||
@ -448,14 +466,18 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
if (results is not null && checkForOutputResolutionChange)
|
||||
{
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, compareBeforeWrite: true))
|
||||
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||
}
|
||||
else if (results is null)
|
||||
{
|
||||
results = GetFaces(resizedFileInfo, propertyHolder, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, facesDirectory);
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, compareBeforeWrite: true))
|
||||
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(D_Face), DateTime.Now));
|
||||
}
|
||||
return results;
|
||||
@ -505,109 +527,20 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
SaveFaces(faceCollection, propertyHolder.ResizedFileInfo, imageFiles);
|
||||
}
|
||||
|
||||
private static List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> GetCollection(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections)
|
||||
{
|
||||
List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> results = new();
|
||||
string[] keys;
|
||||
string directory;
|
||||
string personKey;
|
||||
bool? isWrongYear;
|
||||
TimeSpan timeSpan;
|
||||
DateTime? birthDate;
|
||||
string copyFileName;
|
||||
string copyDirectory;
|
||||
string? relativePath;
|
||||
string isWrongYearFlag;
|
||||
string shortcutFileName;
|
||||
string subDirectoryName;
|
||||
List<int> indices = new();
|
||||
List<D_Face> faceCollection;
|
||||
PropertyHolder propertyHolder;
|
||||
List<(string, D_Face?, (string, string, string, string))> collection;
|
||||
string dFacesContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "(_)");
|
||||
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
|
||||
{
|
||||
indices.Clear();
|
||||
personKey = string.Empty;
|
||||
copyFileName = string.Empty;
|
||||
copyDirectory = string.Empty;
|
||||
propertyHolder = filteredPropertyHolderCollection[i];
|
||||
if (propertyHolder.ImageFileInfo is null)
|
||||
continue;
|
||||
relativePath = Path.GetDirectoryName($"C:{propertyHolder.RelativePath}");
|
||||
if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3)
|
||||
continue;
|
||||
if (propertyHolder.Property?.Id is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileInfo is null)
|
||||
continue;
|
||||
collection = new();
|
||||
if (!propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.ContainsKey(propertyHolder.Property.Id.Value))
|
||||
{
|
||||
faceCollection = new();
|
||||
directory = Path.Combine(dFacesContentDirectory, $"Unnamed{relativePath[2..]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
faceCollection = faceCollections[i];
|
||||
keys = propertyLogic.NamedFaceInfoDeterministicHashCodeIndices[propertyHolder.Property.Id.Value];
|
||||
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileInfo.FullName, propertyHolder.MinimumDateTime.Value);
|
||||
isWrongYearFlag = PropertyHolder.GetWrongYearFlag(isWrongYear);
|
||||
subDirectoryName = $"{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}";
|
||||
if (!faceCollection.Any())
|
||||
directory = Path.Combine(dFacesContentDirectory, $"None{relativePath[2..]}", subDirectoryName);
|
||||
else if (keys.Length != 1)
|
||||
directory = Path.Combine(dFacesContentDirectory, $"Not Supported{relativePath[2..]}", subDirectoryName);
|
||||
else if (faceCollection.Count != 1)
|
||||
directory = Path.Combine(dFacesContentDirectory, $"Many{relativePath[2..]}", subDirectoryName);
|
||||
else
|
||||
{
|
||||
indices.Add(0);
|
||||
personKey = keys[0];
|
||||
if (isWrongYear is not null && !isWrongYear.Value && personKey[..2] is "19" or "20")
|
||||
{
|
||||
birthDate = Shared.Models.Stateless.Methods.IPersonBirthday.Get(personKey);
|
||||
if (birthDate.HasValue)
|
||||
{
|
||||
timeSpan = new(propertyHolder.MinimumDateTime.Value.Ticks - birthDate.Value.Ticks);
|
||||
if (timeSpan.Ticks < 0)
|
||||
subDirectoryName = "!---";
|
||||
else
|
||||
subDirectoryName = $"^{Math.Floor(timeSpan.TotalDays / 365):000}";
|
||||
}
|
||||
}
|
||||
directory = Path.Combine(dFacesContentDirectory, "Shortcuts", personKey, subDirectoryName);
|
||||
if (faceCollection[0].FaceEncoding is not null)
|
||||
copyDirectory = Path.Combine(dFacesContentDirectory, "Images", personKey, subDirectoryName);
|
||||
else
|
||||
copyDirectory = Path.Combine(dFacesContentDirectory, "ImagesBut", personKey, subDirectoryName);
|
||||
copyFileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileInfo.Extension}");
|
||||
}
|
||||
}
|
||||
shortcutFileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
||||
if (string.IsNullOrEmpty(personKey) || !indices.Any())
|
||||
collection.Add(new(personKey, null, (directory, copyDirectory, copyFileName, shortcutFileName)));
|
||||
else
|
||||
{
|
||||
foreach (int index in indices)
|
||||
collection.Add(new(personKey, faceCollection[index], (directory, copyDirectory, copyFileName, shortcutFileName)));
|
||||
}
|
||||
results.Add(new(propertyHolder, collection.ToArray()));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static void SaveShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string[] juliePhares, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections)
|
||||
internal static void SaveShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string[] juliePhares, long ticks, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection)
|
||||
{
|
||||
Person person;
|
||||
string fileName;
|
||||
string fullName;
|
||||
WindowsShortcut windowsShortcut;
|
||||
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
|
||||
List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> collections = GetCollection(configuration, model, predictorModel, propertyLogic, outputResolution, filteredPropertyHolderCollection, faceCollections);
|
||||
foreach ((PropertyHolder propertyHolder, (string personKey, D_Face? face, (string, string, string, string))[] collection) in collections)
|
||||
string dFacesContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), $"({ticks})");
|
||||
List<(PropertyHolder, (string, Shared.Models.Properties.IFace?, (string, string, string, string))[])> collections = PropertyHolder.GetCollection(propertyLogic, filteredPropertyHolderCollection, dFacesContentDirectory);
|
||||
foreach ((PropertyHolder propertyHolder, (string personKey, Shared.Models.Properties.IFace? _, (string, string, string, string))[] collection) in collections)
|
||||
{
|
||||
if (collection.Length != 1)
|
||||
continue;
|
||||
foreach ((string personKey, D_Face? face, (string directory, string copyDirectory, string copyFileName, string shortcutFileName)) in collection)
|
||||
foreach ((string personKey, Shared.Models.Properties.IFace? _, (string directory, string copyDirectory, string copyFileName, string shortcutFileName)) in collection)
|
||||
{
|
||||
if (string.IsNullOrEmpty(personKey))
|
||||
continue;
|
||||
@ -619,7 +552,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
if (!string.IsNullOrEmpty(personKey) && peopleCollection.ContainsKey(personKey))
|
||||
{
|
||||
person = peopleCollection[personKey][0];
|
||||
fullName = Regex.Replace($"{Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name)}.txt", pattern, string.Empty);
|
||||
fullName = string.Concat(Regex.Replace(Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name), pattern, string.Empty), ".txt");
|
||||
File.WriteAllText(Path.Combine(directory, fullName), string.Empty);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ internal class E2_Navigate
|
||||
private void DisplayTags(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string outputResolution, string[] directories, Dictionary<ConsoleKey, int> directoryKeyValuePairs, string[] files, Dictionary<ConsoleKey, int> fileKeyValuePairs)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
bool all = false;
|
||||
FileSystem fileSystem;
|
||||
string requestPath = "/RootResultsDirectory";
|
||||
@ -71,7 +71,7 @@ internal class E2_Navigate
|
||||
private void DisplayFaces(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string outputResolution, string selectedFileFullName)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
string requestPath = "/RootResultsDirectory";
|
||||
string? rootResultsDirectory = Path.GetDirectoryName(Property.Models.Stateless.IResult.GetResultsGroupDirectory(configuration, nameof(B_Metadata)));
|
||||
if (string.IsNullOrEmpty(rootResultsDirectory))
|
||||
@ -95,9 +95,9 @@ internal class E2_Navigate
|
||||
{
|
||||
string result;
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
_Log.Warn(string.Concat("What is the new name for [", Path.GetFileName(subSourceDirectory), "]<", subSourceDirectory, ">?"));
|
||||
string? newDirectoryName = _Console.ReadLine();
|
||||
_Log.Warn("Are you sure y[es] || n[o]?");
|
||||
@ -135,7 +135,7 @@ internal class E2_Navigate
|
||||
internal void Navigate(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string outputResolution)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
string[] subFiles;
|
||||
ConsoleKey consoleKey;
|
||||
string[] subDirectories;
|
||||
|
@ -115,7 +115,7 @@ internal class E3_Rename
|
||||
{
|
||||
List<string[]> results = new();
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
bool add;
|
||||
string to;
|
||||
bool exists;
|
||||
@ -230,7 +230,7 @@ internal class E3_Rename
|
||||
internal void DirectoryRename(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string relativePath, string newDirectoryName)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
string json;
|
||||
FileInfo current;
|
||||
FileInfo fileInfo;
|
||||
@ -299,7 +299,7 @@ internal class E3_Rename
|
||||
if (json.Contains(oldValue))
|
||||
{
|
||||
json = json.Replace(oldValue, newValue);
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, compareBeforeWrite: true))
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ internal class E_Distance
|
||||
return result;
|
||||
}
|
||||
|
||||
private void LoadOrCreateThenSaveDistanceResultsForOutputResolutionsLoop(Property.Models.Configuration configuration, List<List<D_Face>> faceCollections, int subFilesCount, int i, List<D_Face> faceCollection, List<int[]> locationIndicesCollection, List<Tuple<string, DateTime>> subFileTuples, List<FaceEncoding> faceEncodingCollection, List<FaceEncoding> faceEncodingCollections, string fileNameWithoutExtension, string jsonDirectory, string tvsDirectory)
|
||||
private void LoadOrCreateThenSaveDistanceResultsForOutputResolutionsLoop(Property.Models.Configuration configuration, List<List<D_Face>> faceCollections, int subFilesCount, int i, List<D_Face> faceCollection, List<int[]> locationIndicesCollection, List<Tuple<string, DateTime>> subFileTuples, List<FaceEncoding> faceEncodingCollection, List<FaceEncoding> faceEncodingCollections, string fileNameWithoutExtension, string jsonDirectory, string tvsDirectory, bool updateDateWhenMatches, DateTime? updateToWhenMatches)
|
||||
{
|
||||
string text;
|
||||
string json;
|
||||
@ -144,7 +144,7 @@ internal class E_Distance
|
||||
orderedFaceCollection = GetOrderedNoFaceCollection(faceCollections, i, faceCollection[j]);
|
||||
json = JsonSerializer.Serialize(orderedFaceCollection, _WriteIndentedJsonSerializerOptions);
|
||||
jsonFile = Path.Combine(jsonDirectory, $"{j} - {fileNameWithoutExtension}.json");
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, compareBeforeWrite: true))
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: updateToWhenMatches))
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(E_Distance), DateTime.Now));
|
||||
}
|
||||
else
|
||||
@ -162,16 +162,16 @@ internal class E_Distance
|
||||
indicesAndValues = GetValues(faceCollections, locationIndicesCollection, faceDistances);
|
||||
orderedFaceCollection = GetOrderedFaceCollection(faceCollections, locationIndicesCollection, indicesAndValues);
|
||||
text = GetText(fileNameWithoutExtension, faceCollections, locationIndicesCollection, indicesAndValues);
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(tvsFile, text, compareBeforeWrite: true))
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(tvsFile, text, updateDateWhenMatches, compareBeforeWrite: true))
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(E_Distance), DateTime.Now));
|
||||
json = JsonSerializer.Serialize(orderedFaceCollection, _WriteIndentedJsonSerializerOptions);
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, compareBeforeWrite: true))
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches, compareBeforeWrite: true))
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(E_Distance), DateTime.Now));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadOrCreateThenSaveDistanceResultsForOutputResolutions(Property.Models.Configuration configuration, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections, List<string[]> directories)
|
||||
private void LoadOrCreateThenSaveDistanceResultsForOutputResolutions(Property.Models.Configuration configuration, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections, List<string[]> directories, bool updateDateWhenMatches, DateTime? updateToWhenMatches)
|
||||
{
|
||||
FileInfo? fileInfo;
|
||||
string fileNameWithoutExtension;
|
||||
@ -190,7 +190,7 @@ internal class E_Distance
|
||||
if (fileInfo is null)
|
||||
continue;
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
|
||||
LoadOrCreateThenSaveDistanceResultsForOutputResolutionsLoop(configuration, faceCollections, filteredPropertyHolderCollection.Length, i, faceCollections[i], locationIndicesCollection, subFileTuples, faceEncodingCollection, faceEncodingCollections[i], fileNameWithoutExtension, directories[i][0], directories[i][1]);
|
||||
LoadOrCreateThenSaveDistanceResultsForOutputResolutionsLoop(configuration, faceCollections, filteredPropertyHolderCollection.Length, i, faceCollections[i], locationIndicesCollection, subFileTuples, faceEncodingCollection, faceEncodingCollections[i], fileNameWithoutExtension, directories[i][0], directories[i][1], updateDateWhenMatches, updateToWhenMatches);
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,8 +204,10 @@ internal class E_Distance
|
||||
FileInfo? fileInfo;
|
||||
bool check = false;
|
||||
string parentCheck;
|
||||
DateTime? dateTime = null;
|
||||
FileInfo[] fileInfoCollection;
|
||||
string fileNameWithoutExtension;
|
||||
bool updateDateWhenMatches = false;
|
||||
List<string[]> directories = new();
|
||||
System.IO.DirectoryInfo directoryInfo;
|
||||
System.IO.DirectoryInfo tvsDirectoryInfo;
|
||||
@ -264,9 +266,14 @@ internal class E_Distance
|
||||
check = true;
|
||||
else if (dateTimes.Any() && dateTimes.Max() > directoryInfo.LastWriteTime)
|
||||
check = true;
|
||||
if (check && !updateDateWhenMatches)
|
||||
{
|
||||
updateDateWhenMatches = dateTimes.Any() && directoryInfo.Exists && dateTimes.Max() > directoryInfo.LastWriteTime;
|
||||
dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
}
|
||||
}
|
||||
if (check)
|
||||
LoadOrCreateThenSaveDistanceResultsForOutputResolutions(configuration, filteredPropertyHolderCollection, faceCollections, directories);
|
||||
LoadOrCreateThenSaveDistanceResultsForOutputResolutions(configuration, filteredPropertyHolderCollection, faceCollections, directories, updateDateWhenMatches, updateToWhenMatches: dateTime);
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(directoryInfoCollection[0].Replace("<>", "()"));
|
||||
}
|
||||
|
||||
@ -335,7 +342,7 @@ internal class E_Distance
|
||||
_ = Directory.CreateDirectory(jsonDirectory);
|
||||
string json = JsonSerializer.Serialize(faceAndFaceDistanceCollection, _WriteIndentedJsonSerializerOptions);
|
||||
string jsonFile = Path.Combine(jsonDirectory, $"{k} - {fileNameWithoutExtension}.nosj");
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, compareBeforeWrite: true);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
private static Tuple<Shared.Models.Face, double> Get(FaceEncoding faceEncoding, (string, List<Shared.Models.Face>, List<FaceEncoding>) match)
|
||||
@ -350,7 +357,7 @@ internal class E_Distance
|
||||
internal void LoadOrCreateThenSaveDirectoryDistanceResultsForOutputResolutions(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string outputResolution)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
string? relativePath;
|
||||
Shared.Models.Face face;
|
||||
ParallelOptions parallelOptions = new();
|
||||
@ -401,87 +408,89 @@ internal class E_Distance
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, List<(string personKey, D_Face face)>> Convert(string argZero, List<PropertyHolder[]> propertyHolderCollections)
|
||||
public static double GetStandardDeviation(IEnumerable<double> values, double average)
|
||||
{
|
||||
Dictionary<string, List<(string personKey, D_Face face)>> results = new();
|
||||
string key;
|
||||
string personKey;
|
||||
bool? isWrongYear;
|
||||
TimeSpan? timeSpan;
|
||||
string isWrongYearFlag;
|
||||
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
|
||||
{
|
||||
if (!propertyHolderCollection.Any())
|
||||
continue;
|
||||
if (!propertyHolderCollection[0].SourceDirectory.StartsWith(argZero))
|
||||
continue;
|
||||
foreach (PropertyHolder propertyHolder in propertyHolderCollection)
|
||||
{
|
||||
if (propertyHolder.ImageFileInfo is null || propertyHolder.Property is null || !propertyHolder.Named.Any())
|
||||
continue;
|
||||
if (propertyHolder.Named.Count != 1 || propertyHolder.Faces.Count != 1)
|
||||
continue;
|
||||
for (int i = 0; i < propertyHolder.Named.Count; i++)
|
||||
{
|
||||
if (propertyHolder.MinimumDateTime is null)
|
||||
continue;
|
||||
if (propertyHolder.Faces[i] is not D_Face face)
|
||||
continue;
|
||||
timeSpan = propertyHolder.Named[i].TimeSpan;
|
||||
personKey = propertyHolder.Named[i].PersonKey;
|
||||
isWrongYear = propertyHolder.Named[i].IsWrongYear;
|
||||
isWrongYearFlag = PropertyHolder.GetWrongYearFlag(isWrongYear);
|
||||
if (timeSpan is null)
|
||||
key = $"{personKey}\t{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}";
|
||||
else if (timeSpan.Value.Ticks < 0)
|
||||
key = $"{personKey}\t{isWrongYearFlag}!---";
|
||||
else
|
||||
key = $"{personKey}\t^{Math.Floor(timeSpan.Value.TotalDays / 365):000}";
|
||||
if (!results.ContainsKey(key))
|
||||
results.Add(key, new());
|
||||
results[key].Add(new(personKey, face));
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
double result = 0;
|
||||
if (!values.Any())
|
||||
throw new Exception("Collection must have at least one value!");
|
||||
double sum = values.Sum(l => (l - average) * (l - average));
|
||||
result = Math.Sqrt(sum / values.Count());
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void SaveGroupedFaceEncodings(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string argZero, Dictionary<string, List<Shared.Models.Person>> peopleCollection, string outputResolution, List<PropertyHolder[]> propertyHolderCollections)
|
||||
internal static void SaveGroupedFaceEncodings(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string argZero, long ticks, Dictionary<string, List<Shared.Models.Person>> peopleCollection, string outputResolution, List<PropertyHolder[]> propertyHolderCollections)
|
||||
{
|
||||
double lcl;
|
||||
double ucl;
|
||||
string json;
|
||||
double average;
|
||||
int lowestIndex;
|
||||
string checkFile;
|
||||
string directory;
|
||||
string personKey;
|
||||
double lowestAverage;
|
||||
double standardDeviation;
|
||||
FaceEncoding faceEncoding;
|
||||
List<double> faceDistances;
|
||||
List<double[]> rawEncodings;
|
||||
Shared.Models.Person person;
|
||||
List<FaceEncoding> faceEncodings;
|
||||
List<string> checkDirectories = new();
|
||||
List<Shared.Models.Properties.IFace> collection;
|
||||
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
|
||||
Dictionary<string, List<(string personKey, D_Face face)>> keyValuePairs = Convert(argZero, propertyHolderCollections);
|
||||
string eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[_]");
|
||||
foreach (KeyValuePair<string, List<(string personKey, D_Face face)>> keyValuePair in keyValuePairs)
|
||||
string eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), $"[{ticks}]");
|
||||
List<(string, Shared.Models.PersonBirthday, Shared.Models.Properties.IFace)[]> collection = PropertyHolder.GetCollection(argZero, propertyHolderCollections, eDistanceCollectionDirectory);
|
||||
foreach ((string, Shared.Models.PersonBirthday, Shared.Models.Properties.IFace)[] group in collection)
|
||||
{
|
||||
collection = new();
|
||||
lowestIndex = 0;
|
||||
rawEncodings = new();
|
||||
faceEncodings = new();
|
||||
checkDirectories.Clear();
|
||||
checkFile = string.Empty;
|
||||
foreach ((string personKey, D_Face face) in keyValuePair.Value)
|
||||
lowestAverage = double.MaxValue;
|
||||
foreach ((string directory, Shared.Models.PersonBirthday personBirthday, Shared.Models.Properties.IFace @interface) in group)
|
||||
{
|
||||
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
||||
if (string.IsNullOrEmpty(personKey) || !peopleCollection.ContainsKey(personKey))
|
||||
continue;
|
||||
if (@interface is not D_Face face || !face.Populated)
|
||||
continue;
|
||||
person = peopleCollection[personKey][0];
|
||||
directory = Path.Combine(eDistanceCollectionDirectory, $"{personKey}{keyValuePair.Key}");
|
||||
checkFile = Path.Combine(directory, Regex.Replace($"{Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name)}.json", pattern, string.Empty));
|
||||
faceEncoding = FaceRecognition.LoadFaceEncoding(face.FaceEncoding.RawEncoding);
|
||||
checkFile = string.Concat(directory, " - ", Regex.Replace(Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name), pattern, string.Empty), ".json");
|
||||
checkDirectories.Add(directory);
|
||||
collection.Add(face);
|
||||
faceEncodings.Add(faceEncoding);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(checkFile) && checkDirectories.Any())
|
||||
if (string.IsNullOrEmpty(checkFile) || !checkDirectories.Any() || faceEncodings.Count < 2)
|
||||
continue;
|
||||
foreach (string checkDirectory in checkDirectories.Distinct())
|
||||
{
|
||||
foreach (string checkDirectory in checkDirectories)
|
||||
{
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
json = JsonSerializer.Serialize(collection, new JsonSerializerOptions { WriteIndented = true });
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, compareBeforeWrite: true);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
for (int i = 0; i < faceEncodings.Count; i++)
|
||||
{
|
||||
faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncodings[i]);
|
||||
average = faceDistances.Average();
|
||||
if (average > lowestAverage)
|
||||
continue;
|
||||
lowestIndex = i;
|
||||
lowestAverage = average;
|
||||
}
|
||||
faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncodings[lowestIndex]);
|
||||
average = faceDistances.Average();
|
||||
if (average != lowestAverage)
|
||||
continue;
|
||||
standardDeviation = GetStandardDeviation(faceDistances, average);
|
||||
lcl = average - (standardDeviation * 3);
|
||||
ucl = average + (standardDeviation * 3);
|
||||
for (int i = 0; i < faceEncodings.Count; i++)
|
||||
{
|
||||
if (faceDistances[i] < lcl || faceDistances[i] > ucl)
|
||||
continue;
|
||||
rawEncodings.Add(faceEncodings[i].GetRawEncoding());
|
||||
}
|
||||
// outOfControl = faceEncodings.Count - rawEncodings.Count;
|
||||
json = JsonSerializer.Serialize(rawEncodings, new JsonSerializerOptions { WriteIndented = true });
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ internal class F_Random
|
||||
{
|
||||
bool result = false;
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
string? checkDirectory = Path.GetFullPath(directory);
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
@ -73,7 +73,7 @@ internal class F_Random
|
||||
relativePaths = (from l in relativePaths orderby random.NextDouble() select l).ToList();
|
||||
jsonFile = Path.Combine(fRandomCollectionDirectory, $"{dateTime.AddDays(i):MM-dd}.json");
|
||||
json = JsonSerializer.Serialize(relativePaths, _WriteIndentedJsonSerializerOptions);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, compareBeforeWrite: false);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches: false, compareBeforeWrite: false);
|
||||
if (!_Configuration.SaveFullYearOfRandomFiles.Value)
|
||||
break;
|
||||
}
|
||||
@ -83,7 +83,7 @@ internal class F_Random
|
||||
ignoreRelativePaths = (from l in ignoreRelativePaths orderby random.NextDouble() select l).ToList();
|
||||
jsonFile = Path.Combine(fRandomCollectionDirectory, "01-01.txt");
|
||||
json = JsonSerializer.Serialize(ignoreRelativePaths, _WriteIndentedJsonSerializerOptions);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, compareBeforeWrite: false);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches: false, compareBeforeWrite: false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class G2_Identify : Shared.Models.Properties.IIdentify, IIdentify
|
||||
json = JsonSerializer.Serialize(resultKeyValuePairs, _WriteIndentedJsonSerializerOptions);
|
||||
if (!isEnvironment.DebuggerWasAttachedDuringConstructor)
|
||||
throw new Exception("Only allowed when debugger is attached during constructor!");
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(named.FullName, json, compareBeforeWrite: true);
|
||||
_ = Property.Models.Stateless.IPath.WriteAllText(named.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ public class G2_Identify : Shared.Models.Properties.IIdentify, IIdentify
|
||||
_ = Directory.CreateDirectory(directoryFullName);
|
||||
jsonFile = string.Concat(g2IdentifyCollectionDirectory, keyValuePair.Key, ".json");
|
||||
json = JsonSerializer.Serialize(keyValuePair.Value, _WriteIndentedJsonSerializerOptions);
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, compareBeforeWrite: true))
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public class G_Index : Shared.Models.Properties.IIndex, IIndex
|
||||
dateTime = (from l in dateTimes where l.HasValue select l.Value).Min();
|
||||
indexInfo = new(dateTime, maxIndexPlusOne, tuple.Item1);
|
||||
json = JsonSerializer.Serialize(indexInfo, _WriteIndentedJsonSerializerOptions);
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(tuple.Item2, json, compareBeforeWrite: true))
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(tuple.Item2, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -114,7 +114,7 @@ public class G_Index : Shared.Models.Properties.IIndex, IIndex
|
||||
indices = (from l in tuple.Item2 select l.Value).ToArray();
|
||||
directoryInfoCollection = Property.Models.Stateless.IResult.GetDirectoryInfoCollection(configuration, model, predictorModel, tuple.Item1, nameof(G_Index), outputResolution, includeResizeGroup: false, includeModel: false, includePredictorModel: false, contentDescription: string.Empty, singletonDescription: string.Empty, collectionDescription: "Unknown A");
|
||||
json = JsonSerializer.Serialize(indices, _WriteIndentedJsonSerializerOptions);
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(string.Concat(directoryInfoCollection[0].Replace("<>", "[]"), ".json"), json, compareBeforeWrite: true))
|
||||
if (!Property.Models.Stateless.IPath.WriteAllText(string.Concat(directoryInfoCollection[0].Replace("<>", "[]"), ".json"), json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,8 @@
|
||||
"MaxItemsInDistanceCollection": 50,
|
||||
"ModelDirectory": "C:/GitHub/dlib-models",
|
||||
"ModelName": "Hog",
|
||||
"NumJitters": 1,
|
||||
"NumberOfJitters": 1,
|
||||
"NumberOfTimesToUpsample": 1,
|
||||
"OutputExtension": ".jpg",
|
||||
"OutputQuality": 95,
|
||||
"OverrideForFaceImages": false,
|
||||
|
@ -65,7 +65,8 @@
|
||||
"MaxItemsInDistanceCollection": 50,
|
||||
"ModelDirectory": "L:/GitHub/dlib-models",
|
||||
"ModelName": "Hog",
|
||||
"NumJitters": 1,
|
||||
"NumberOfJitters": 1,
|
||||
"NumberOfTimesToUpsample": 1,
|
||||
"OutputExtension": ".jpg",
|
||||
"OutputQuality": 95,
|
||||
"OverrideForFaceImages": false,
|
||||
|
@ -65,7 +65,8 @@
|
||||
"MaxItemsInDistanceCollection": 50,
|
||||
"ModelDirectory": "C:/GitHub/dlib-models",
|
||||
"ModelName": "Hog",
|
||||
"NumJitters": 1,
|
||||
"NumberOfJitters": 1,
|
||||
"NumberOfTimesToUpsample": 1,
|
||||
"OutputExtension": ".jpg",
|
||||
"OutputQuality": 95,
|
||||
"OverrideForFaceImages": false,
|
||||
|
Reference in New Issue
Block a user