Table of Contents

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

cacheDirectory string

Directory 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

url string

URL to download from.

localPath string

Local path to save to.

progress IProgress<double>

Optional progress callback.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

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

url string

URL to download from.

fileName string

Local filename to save as.

progress IProgress<double>

Optional progress callback (0.0 to 1.0).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<string>

Path to the downloaded or cached weight file.

GetCachePath(string)

Gets the cached path for a weight file.

public string GetCachePath(string fileName)

Parameters

fileName string

The 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

fileName string

The 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

fileName string

The filename to remove.

Returns

bool

True if the file was removed.