Open beccamc opened 1 year ago
Does the image has a loadData Method? does this include the template or discuss load method for image
Nope, I need to provide the source code!
Here's an example of loading images from folder.
public static IDataView LoadImagesFromFolder(MLContext context, string folder)
{
var res = new List<ModelInput>();
var allowedImageExtensions = new[] { ".png", ".jpg", ".jpeg", ".gif" };
DirectoryInfo rootDirectoryInfo = new DirectoryInfo(folder);
DirectoryInfo[] subDirectories = rootDirectoryInfo.GetDirectories();
if (subDirectories.Length == 0)
{
throw new Exception("fail to find subdirectories");
}
foreach (DirectoryInfo directory in subDirectories)
{
var imageList = directory.EnumerateFiles().Where(f => allowedImageExtensions.Contains(f.Extension.ToLower()));
if (imageList.Count() > 0)
{
res.AddRange(imageList.Select(i => new ModelInput
{
Label = directory.Name,
ImageSource = File.ReadAllBytes(i.FullName),
}));
}
}
return context.Data.LoadFromEnumerable(res);
}
## Example for azure image classification
```csharp
public static IDataView LoadImagesFromFolder(MLContext context, string folder)
{
var res = new List<ModelInput>();
var allowedImageExtensions = new[] { ".png", ".jpg", ".jpeg", ".gif" };
DirectoryInfo rootDirectoryInfo = new DirectoryInfo(folder);
DirectoryInfo[] subDirectories = rootDirectoryInfo.GetDirectories();
if (subDirectories.Length == 0)
{
throw new Exception("fail to find subdirectories");
}
foreach (DirectoryInfo directory in subDirectories)
{
var imageList = directory.EnumerateFiles().Where(f => allowedImageExtensions.Contains(f.Extension.ToLower()));
if (imageList.Count() > 0)
{
res.AddRange(imageList.Select(i => new ModelInput
{
Label = directory.Name,
ImageSource = MLImage.LoadFromFile(i.FullName), // this is the only difference comparing to local image training
}));
}
}
return context.Data.LoadFromEnumerable(res);
}
for Azure, it should be CreateFromFile
instead of LoadFromFile
.
Is that right ?@LittleLittleCloud
Image classification doesn't have a sample load method for IDataView.
@beccamc to provide code for this scenario.