Last active
August 28, 2017 15:03
-
-
Save fumiya-kume/7eeb66e778aba8f49d6205bd462107c6 to your computer and use it in GitHub Desktop.
[WIP]Custom Vision Services を使ってSDKで学習させてみた ref: http://qiita.com/fumiya-kume/items/cf2b52a3ab4c1a52b6ee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static TrainingApi GetCustomVisionClient(string CustomVisionSbscriotionKey) | |
{ | |
var TraningCredinental = new TrainingApiCredentials(CustomVisionSbscriotionKey); | |
return new TrainingApi(TraningCredinental); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<List<Member>> GetMemberInfoFromBingImageSeatchAsync(string MemberName, string BingSubscriotionKey) | |
{ | |
var client = new HttpClient(); | |
// Request headers | |
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", BingSubscriotionKey); | |
// 長濱ねるちゃんの時は、学習素材をちょっと多めに取得する | |
var count = MemberName == "長濱ねる" ? 39 : 32; | |
var uri = $"https://api.cognitive.microsoft.com/bing/v5.0/images/search?q={MemberName}&count={count}"; | |
var response = await client.GetAsync(uri); | |
var responseText = await response.Content.ReadAsStringAsync(); | |
var BingImageURLList = JsonConvert.DeserializeObject<BingImageSearchObject>(responseText); | |
var BingMemberList = BingImageURLList.value | |
.Select(value => value.contentUrl) | |
.Select(image => new Member() { Name = MemberName, ImageURL = image }) | |
.ToList(); | |
return BingMemberList; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TraningAPI = GetCustomVisionClient(CustomVisionSubscriptionKey); | |
var Batch = new ImageUrlCreateBatch | |
{ | |
TagIds = GetTag(TraningAPI, MemberList.Where(member => member.Name == memberName).Select(memberInfo => memberInfo.Name).First()), | |
Urls = MemberList.Where(member => member.Name == memberName).Select(memberInfo => memberInfo.ImageURL).ToList() | |
}; | |
TraningAPI.CreateImagesFromUrls(GetKEYAKIProjectID(TraningAPI), Batch); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var queryString = HttpUtility.ParseQueryString(string.Empty); | |
// Request headers | |
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}"); | |
// Request parameters | |
queryString["q"] = "bill gates"; | |
queryString["count"] = "10"; | |
queryString["offset"] = "0"; | |
queryString["mkt"] = "en-us"; | |
queryString["safesearch"] = "Moderate"; | |
var uri = "https://api.cognitive.microsoft.com/bing/v5.0/search?" + queryString; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var uri = $"https://api.cognitive.microsoft.com/bing/v5.0/images/search?q={MemberName}&count={count}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment