Class WeightDownloader
- Namespace
- AiDotNet.ComputerVision.Weights
- Assembly
- AiDotNet.dll
Downloads and caches pre-trained model weights from remote URLs.
public class WeightDownloader
- Inheritance
-
WeightDownloader
- Inherited Members
Remarks
For Beginners: Pre-trained weights are model parameters that have been trained on large datasets (like COCO or ImageNet). Instead of training from scratch, you can download these weights and either use them directly or fine-tune them on your own data. This class handles downloading and caching these weight files.
Constructors
WeightDownloader()
Creates a new weight downloader with the default cache directory.
public WeightDownloader()
WeightDownloader(string)
Creates a new weight downloader with a custom cache directory.
public WeightDownloader(string cacheDirectory)
Parameters
cacheDirectorystringDirectory to store downloaded weights.
Methods
ClearCache()
Clears all cached weights.
public void ClearCache()
DownloadAsync(string, string, IProgress<double>?, CancellationToken)
Downloads a weight file from a URL.
public Task DownloadAsync(string url, string localPath, IProgress<double>? progress = null, CancellationToken cancellationToken = default)
Parameters
urlstringURL to download from.
localPathstringLocal path to save to.
progressIProgress<double>Optional progress callback.
cancellationTokenCancellationTokenCancellation token.
Returns
DownloadIfNeededAsync(string, string, IProgress<double>?, CancellationToken)
Downloads weights if not already cached.
public Task<string> DownloadIfNeededAsync(string url, string fileName, IProgress<double>? progress = null, CancellationToken cancellationToken = default)
Parameters
urlstringURL to download from.
fileNamestringLocal filename to save as.
progressIProgress<double>Optional progress callback (0.0 to 1.0).
cancellationTokenCancellationTokenCancellation token.
Returns
GetCachePath(string)
Gets the cached path for a weight file.
public string GetCachePath(string fileName)
Parameters
fileNamestringThe filename.
Returns
- string
Full path to the cached file (may not exist).
GetCacheSize()
Gets the total size of cached weights in bytes.
public long GetCacheSize()
Returns
- long
Total cache size in bytes.
GetDefaultCacheDirectory()
Gets the default cache directory for storing weights.
public static string GetDefaultCacheDirectory()
Returns
- string
The default cache directory path.
IsCached(string)
Checks if weights are already cached.
public bool IsCached(string fileName)
Parameters
fileNamestringThe filename to check for.
Returns
- bool
True if the file exists in cache.
RemoveFromCache(string)
Removes a weight file from cache.
public bool RemoveFromCache(string fileName)
Parameters
fileNamestringThe filename to remove.
Returns
- bool
True if the file was removed.