Browse Source

added utils class for the Hub

pull/302/head
Kerry Jiang 6 years ago
parent
commit
15d921fbbb
1 changed files with 36 additions and 0 deletions
  1. +36
    -0
      src/TensorFlowHub/Utils.cs

+ 36
- 0
src/TensorFlowHub/Utils.cs View File

@@ -0,0 +1,36 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using NumSharp;

namespace Tensorflow.Hub
{
public static class Utils
{
public static async Task DownloadAsync<TDataSet>(this IModelLoader<TDataSet> modelLoader, string url, string saveTo)
where TDataSet : IDataSet
{
var dir = Path.GetDirectoryName(saveTo);
var fileName = Path.GetFileName(saveTo);
await modelLoader.DownloadAsync(url, dir, fileName);
}

public static async Task DownloadAsync<TDataSet>(this IModelLoader<TDataSet> modelLoader, string url, string dirSaveTo, string fileName)
where TDataSet : IDataSet
{
if (!Path.IsPathRooted(dirSaveTo))
dirSaveTo = Path.Combine(AppContext.BaseDirectory, dirSaveTo);

if (!Directory.Exists(dirSaveTo))
Directory.CreateDirectory(dirSaveTo);
using (var wc = new WebClient())
{
await wc.DownloadFileTaskAsync(url, Path.Combine(dirSaveTo, fileName));
}
}
}
}

Loading…
Cancel
Save