public static bool RemoveImagesByTag(Guid projectId, string trainingKey, Guid tagId) { try { bool result = CSUploadAndTrain.DeleteTagAsync(trainingKey, projectId, tagId.ToString()).Result; Console.WriteLine($"delete tagid {tagId}! {result}"); return(true); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.InnerException.ToString()); return(false); } }
public static bool Train(Guid projectId, string trainingKey) { // Create the Api, passing in the training key // Now there are images with tags start training the project Console.WriteLine("\tTraining"); try { var iteration = CSUploadAndTrain.TrainProject(trainingKey, projectId).Result; if (iteration.Id == null) { return(false); } // The returned iteration will be in progress, and can be queried periodically to see when it has completed while (iteration.Status == "Training") { Thread.Sleep(1000); // Re-query the iteration to get it's updated status iteration = CSUploadAndTrain.GetIteration(trainingKey, projectId, iteration.Id).Result; if (iteration.Status == null) { return(false); } Console.WriteLine(iteration.Status); } // The iteration is now trained. Make it the default project endpoint iteration.IsDefault = true; var updateResponse = CSUploadAndTrain.UpdateIteration(trainingKey, projectId, iteration).Result; if (updateResponse.StatusCode != HttpStatusCode.OK) { Console.WriteLine(updateResponse); return(false); } Console.WriteLine("Done!\n"); return(true); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.InnerException); return(false); } }
public static Guid UploadImageAndReturnTag(Guid projectId, string trainingKey, List <string> images) { // Create the Api, passing in the training key // Make new tag in the project Guid newTag = Guid.NewGuid(); var newAnimalTag = CSUploadAndTrain.CreateTagAsync(trainingKey, projectId, newTag.ToString()).Result; // Images can be uploaded one at a time try { foreach (var image in images) { using (var stream = new MemoryStream(File.ReadAllBytes(image))) { var response = CSUploadAndTrain.CreateImagesFromDataAsync(trainingKey, projectId, stream, new List <string>() { newAnimalTag.Id.ToString() }).Result; if (response.StatusCode != HttpStatusCode.OK) { Console.WriteLine(response); return(Guid.Empty); } } } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.InnerException.ToString()); return(Guid.Empty); } return(newAnimalTag.Id); }