ModelDownloader class
Fetches pretrained models and puts them in a directory of your choosing.
final downloader = ModelDownloader();
try {
final file = await downloader.download(
PretrainedModel.compact,
directory: 'assets/models',
onProgress: (p) => print(p),
);
final classifier = FastTextClassifier.fromBytes(await file.readAsBytes());
} finally {
await downloader.close();
}
A model already present in the directory is returned as is, unless it
turns out not to be a model, in which case it is thrown away and fetched
again; pass force: true to refetch regardless. The download goes to a
.part file and is renamed into place only once it is complete and checks
out, so an interrupted run never leaves a half-written model behind.
Constructors
- ModelDownloader({Uri? baseUrl, HttpClient? httpClient, Duration connectionTimeout = const Duration(seconds: 30), Duration stallTimeout = const Duration(seconds: 60)})
- Creates a downloader.
Properties
- baseUrl → Uri
-
Where models are fetched from; ends with a slash.
final
- connectionTimeout → Duration
-
How long the server has to answer at all.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stallTimeout → Duration
-
How long the body may go quiet before the download is abandoned.
final
Methods
-
close(
) → Future< void> - Releases the underlying HttpClient, unless it was passed in.
-
download(
PretrainedModel model, {required String directory, bool force = false, void onProgress(DownloadProgress progress)?}) → Future< File> -
Downloads
modelintodirectory, creating the directory if needed. -
fileIn(
String directory, PretrainedModel model) → File -
Where download will put
modelinsidedirectory. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
urlOf(
PretrainedModel model) → Uri -
The address download will fetch
modelfrom.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- defaultBaseUrl → Uri
-
Where Facebook publishes the models.
final