Skip to content

Commit 33c75c1

Browse files
committed
chore(visual recognition): Apply manual changes
1 parent 58d87d7 commit 33c75c1

File tree

2 files changed

+14
-233
lines changed

2 files changed

+14
-233
lines changed

src/IBM.WatsonDeveloperCloud.VisualRecognition.v3/IVisualRecognitionService.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ public partial interface IVisualRecognitionService
2424
{
2525
ClassifiedImages Classify(System.IO.FileStream imagesFile = null, string acceptLanguage = null, string url = null, float? threshold = null, List<string> owners = null, List<string> classifierIds = null, string imagesFileContentType = null, Dictionary<string, object> customData = null);
2626
DetectedFaces DetectFaces(System.IO.FileStream imagesFile = null, string url = null, string imagesFileContentType = null, Dictionary<string, object> customData = null);
27-
Classifier CreateClassifier(string name, System.IO.FileStream classnamePositiveExamples, System.IO.FileStream negativeExamples = null, Dictionary<string, object> customData = null);
2827
BaseModel DeleteClassifier(string classifierId, Dictionary<string, object> customData = null);
2928
Classifier GetClassifier(string classifierId, Dictionary<string, object> customData = null);
3029
Classifiers ListClassifiers(bool? verbose = null, Dictionary<string, object> customData = null);
31-
Classifier UpdateClassifier(string classifierId, System.IO.FileStream classnamePositiveExamples = null, System.IO.FileStream negativeExamples = null, Dictionary<string, object> customData = null);
32-
System.IO.MemoryStream GetCoreMlModel(string classifierId, Dictionary<string, object> customData = null);
3330
BaseModel DeleteUserData(string customerId, Dictionary<string, object> customData = null);
3431
}
3532
}

src/IBM.WatsonDeveloperCloud.VisualRecognition.v3/VisualRecognitionService.cs

Lines changed: 14 additions & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ public VisualRecognitionService() : base(SERVICE_NAME, URL)
4545
this.Endpoint = URL;
4646
}
4747

48-
public VisualRecognitionService(, string versionDate) : this()
48+
[Obsolete("Authentication using legacy apikey is deprecated. Please authenticate using TokenOptions.")]
49+
public VisualRecognitionService(string apikey, string versionDate) : this()
4950
{
50-
if(string.IsNullOrEmpty(versionDate))
51+
if (string.IsNullOrEmpty(apikey))
52+
throw new ArgumentNullException(nameof(apikey));
53+
54+
this.SetCredential(apikey);
55+
56+
if (string.IsNullOrEmpty(versionDate))
5157
throw new ArgumentNullException("versionDate cannot be null.");
5258

5359
VersionDate = versionDate;
@@ -174,6 +180,7 @@ public ClassifiedImages Classify(System.IO.FileStream imagesFile = null, string
174180
IClient client;
175181
if(_tokenManager == null)
176182
{
183+
client = this.Client;
177184
}
178185
else
179186
{
@@ -260,6 +267,7 @@ public DetectedFaces DetectFaces(System.IO.FileStream imagesFile = null, string
260267
IClient client;
261268
if(_tokenManager == null)
262269
{
270+
client = this.Client;
263271
}
264272
else
265273
{
@@ -283,100 +291,6 @@ public DetectedFaces DetectFaces(System.IO.FileStream imagesFile = null, string
283291

284292
return result;
285293
}
286-
/// <summary>
287-
/// Create a classifier.
288-
///
289-
/// Train a new multi-faceted classifier on the uploaded image data. Create your custom classifier with positive
290-
/// or negative examples. Include at least two sets of examples, either two positive example files or one
291-
/// positive and one negative file. You can upload a maximum of 256 MB per call.
292-
///
293-
/// Encode all names in UTF-8 if they contain non-ASCII characters (.zip and image file names, and classifier
294-
/// and class names). The service assumes UTF-8 encoding if it encounters non-ASCII characters.
295-
/// </summary>
296-
/// <param name="name">The name of the new classifier. Encode special characters in UTF-8.</param>
297-
/// <param name="classnamePositiveExamples">A .zip file of images that depict the visual subject of a class in
298-
/// the new classifier. You can include more than one positive example file in a call.
299-
///
300-
/// Specify the parameter name by appending `_positive_examples` to the class name. For example,
301-
/// `goldenretriever_positive_examples` creates the class **goldenretriever**.
302-
///
303-
/// Include at least 10 images in .jpg or .png format. The minimum recommended image resolution is 32X32 pixels.
304-
/// The maximum number of images is 10,000 images or 100 MB per .zip file.
305-
///
306-
/// Encode special characters in the file name in UTF-8.</param>
307-
/// <param name="negativeExamples">A .zip file of images that do not depict the visual subject of any of the
308-
/// classes of the new classifier. Must contain a minimum of 10 images.
309-
///
310-
/// Encode special characters in the file name in UTF-8. (optional)</param>
311-
/// <param name="customData">Custom data object to pass data including custom request headers.</param>
312-
/// <returns><see cref="Classifier" />Classifier</returns>
313-
public Classifier CreateClassifier(string name, System.IO.FileStream classnamePositiveExamples, System.IO.FileStream negativeExamples = null, Dictionary<string, object> customData = null)
314-
{
315-
if (string.IsNullOrEmpty(name))
316-
throw new ArgumentNullException(nameof(name));
317-
if (classnamePositiveExamples == null)
318-
throw new ArgumentNullException(nameof(classnamePositiveExamples));
319-
320-
if(string.IsNullOrEmpty(VersionDate))
321-
throw new ArgumentNullException("versionDate cannot be null.");
322-
323-
Classifier result = null;
324-
325-
try
326-
{
327-
var formData = new MultipartFormDataContent();
328-
329-
if (name != null)
330-
{
331-
var nameContent = new StringContent(name, Encoding.UTF8, HttpMediaType.TEXT_PLAIN);
332-
nameContent.Headers.ContentType = null;
333-
formData.Add(nameContent, "name");
334-
}
335-
336-
if (classnamePositiveExamples != null)
337-
{
338-
var classnamePositiveExamplesContent = new ByteArrayContent((classnamePositiveExamples as Stream).ReadAllBytes());
339-
System.Net.Http.Headers.MediaTypeHeaderValue contentType;
340-
System.Net.Http.Headers.MediaTypeHeaderValue.TryParse("application/octet-stream", out contentType);
341-
classnamePositiveExamplesContent.Headers.ContentType = contentType;
342-
formData.Add(classnamePositiveExamplesContent, "classname_positive_examples", classnamePositiveExamples.Name);
343-
}
344-
345-
if (negativeExamples != null)
346-
{
347-
var negativeExamplesContent = new ByteArrayContent((negativeExamples as Stream).ReadAllBytes());
348-
System.Net.Http.Headers.MediaTypeHeaderValue contentType;
349-
System.Net.Http.Headers.MediaTypeHeaderValue.TryParse("application/octet-stream", out contentType);
350-
negativeExamplesContent.Headers.ContentType = contentType;
351-
formData.Add(negativeExamplesContent, "negative_examples", negativeExamples.Name);
352-
}
353-
354-
IClient client;
355-
if(_tokenManager == null)
356-
{
357-
}
358-
else
359-
{
360-
client = this.Client.WithAuthentication(_tokenManager.GetToken());
361-
}
362-
var restRequest = client.PostAsync($"{this.Endpoint}/v3/classifiers");
363-
364-
restRequest.WithArgument("version", VersionDate);
365-
restRequest.WithBodyContent(formData);
366-
if (customData != null)
367-
restRequest.WithCustomData(customData);
368-
result = restRequest.As<Classifier>().Result;
369-
if(result == null)
370-
result = new Classifier();
371-
result.CustomData = restRequest.CustomData;
372-
}
373-
catch(AggregateException ae)
374-
{
375-
throw ae.Flatten();
376-
}
377-
378-
return result;
379-
}
380294

381295
/// <summary>
382296
/// Delete a classifier.
@@ -399,6 +313,7 @@ public BaseModel DeleteClassifier(string classifierId, Dictionary<string, object
399313
IClient client;
400314
if(_tokenManager == null)
401315
{
316+
client = this.Client;
402317
}
403318
else
404319
{
@@ -445,6 +360,7 @@ public Classifier GetClassifier(string classifierId, Dictionary<string, object>
445360
IClient client;
446361
if(_tokenManager == null)
447362
{
363+
client = this.Client;
448364
}
449365
else
450366
{
@@ -488,6 +404,7 @@ public Classifiers ListClassifiers(bool? verbose = null, Dictionary<string, obje
488404
IClient client;
489405
if(_tokenManager == null)
490406
{
407+
client = this.Client;
491408
}
492409
else
493410
{
@@ -513,140 +430,6 @@ public Classifiers ListClassifiers(bool? verbose = null, Dictionary<string, obje
513430
return result;
514431
}
515432

516-
/// <summary>
517-
/// Update a classifier.
518-
///
519-
/// Update a custom classifier by adding new positive or negative classes (examples) or by adding new images to
520-
/// existing classes. You must supply at least one set of positive or negative examples. For details, see
521-
/// [Updating custom
522-
/// classifiers](https://console.bluemix.net/docs/services/visual-recognition/customizing.html#updating-custom-classifiers).
523-
///
524-
/// Encode all names in UTF-8 if they contain non-ASCII characters (.zip and image file names, and classifier
525-
/// and class names). The service assumes UTF-8 encoding if it encounters non-ASCII characters.
526-
///
527-
/// **Tip:** Don't make retraining calls on a classifier until the status is ready. When you submit retraining
528-
/// requests in parallel, the last request overwrites the previous requests. The retrained property shows the
529-
/// last time the classifier retraining finished.
530-
/// </summary>
531-
/// <param name="classifierId">The ID of the classifier.</param>
532-
/// <param name="classnamePositiveExamples">A .zip file of images that depict the visual subject of a class in
533-
/// the classifier. The positive examples create or update classes in the classifier. You can include more than
534-
/// one positive example file in a call.
535-
///
536-
/// Specify the parameter name by appending `_positive_examples` to the class name. For example,
537-
/// `goldenretriever_positive_examples` creates the class `goldenretriever`.
538-
///
539-
/// Include at least 10 images in .jpg or .png format. The minimum recommended image resolution is 32X32 pixels.
540-
/// The maximum number of images is 10,000 images or 100 MB per .zip file.
541-
///
542-
/// Encode special characters in the file name in UTF-8. (optional)</param>
543-
/// <param name="negativeExamples">A .zip file of images that do not depict the visual subject of any of the
544-
/// classes of the new classifier. Must contain a minimum of 10 images.
545-
///
546-
/// Encode special characters in the file name in UTF-8. (optional)</param>
547-
/// <param name="customData">Custom data object to pass data including custom request headers.</param>
548-
/// <returns><see cref="Classifier" />Classifier</returns>
549-
public Classifier UpdateClassifier(string classifierId, System.IO.FileStream classnamePositiveExamples = null, System.IO.FileStream negativeExamples = null, Dictionary<string, object> customData = null)
550-
{
551-
if (string.IsNullOrEmpty(classifierId))
552-
throw new ArgumentNullException(nameof(classifierId));
553-
554-
if(string.IsNullOrEmpty(VersionDate))
555-
throw new ArgumentNullException("versionDate cannot be null.");
556-
557-
Classifier result = null;
558-
559-
try
560-
{
561-
var formData = new MultipartFormDataContent();
562-
563-
if (classnamePositiveExamples != null)
564-
{
565-
var classnamePositiveExamplesContent = new ByteArrayContent((classnamePositiveExamples as Stream).ReadAllBytes());
566-
System.Net.Http.Headers.MediaTypeHeaderValue contentType;
567-
System.Net.Http.Headers.MediaTypeHeaderValue.TryParse("application/octet-stream", out contentType);
568-
classnamePositiveExamplesContent.Headers.ContentType = contentType;
569-
formData.Add(classnamePositiveExamplesContent, "classname_positive_examples", classnamePositiveExamples.Name);
570-
}
571-
572-
if (negativeExamples != null)
573-
{
574-
var negativeExamplesContent = new ByteArrayContent((negativeExamples as Stream).ReadAllBytes());
575-
System.Net.Http.Headers.MediaTypeHeaderValue contentType;
576-
System.Net.Http.Headers.MediaTypeHeaderValue.TryParse("application/octet-stream", out contentType);
577-
negativeExamplesContent.Headers.ContentType = contentType;
578-
formData.Add(negativeExamplesContent, "negative_examples", negativeExamples.Name);
579-
}
580-
581-
IClient client;
582-
if(_tokenManager == null)
583-
{
584-
}
585-
else
586-
{
587-
client = this.Client.WithAuthentication(_tokenManager.GetToken());
588-
}
589-
var restRequest = client.PostAsync($"{this.Endpoint}/v3/classifiers/{classifierId}");
590-
591-
restRequest.WithArgument("version", VersionDate);
592-
restRequest.WithBodyContent(formData);
593-
if (customData != null)
594-
restRequest.WithCustomData(customData);
595-
result = restRequest.As<Classifier>().Result;
596-
if(result == null)
597-
result = new Classifier();
598-
result.CustomData = restRequest.CustomData;
599-
}
600-
catch(AggregateException ae)
601-
{
602-
throw ae.Flatten();
603-
}
604-
605-
return result;
606-
}
607-
/// <summary>
608-
/// Retrieve a Core ML model of a classifier.
609-
///
610-
/// Download a Core ML model file (.mlmodel) of a custom classifier that returns <tt>"core_ml_enabled":
611-
/// true</tt> in the classifier details.
612-
/// </summary>
613-
/// <param name="classifierId">The ID of the classifier.</param>
614-
/// <param name="customData">Custom data object to pass data including custom request headers.</param>
615-
/// <returns><see cref="System.IO.FileStream" />System.IO.FileStream</returns>
616-
public System.IO.MemoryStream GetCoreMlModel(string classifierId, Dictionary<string, object> customData = null)
617-
{
618-
if (string.IsNullOrEmpty(classifierId))
619-
throw new ArgumentNullException(nameof(classifierId));
620-
621-
if(string.IsNullOrEmpty(VersionDate))
622-
throw new ArgumentNullException("versionDate cannot be null.");
623-
624-
System.IO.MemoryStream result = null;
625-
626-
try
627-
{
628-
IClient client;
629-
if(_tokenManager == null)
630-
{
631-
}
632-
else
633-
{
634-
client = this.Client.WithAuthentication(_tokenManager.GetToken());
635-
}
636-
var restRequest = client.GetAsync($"{this.Endpoint}/v3/classifiers/{classifierId}/core_ml_model");
637-
638-
restRequest.WithArgument("version", VersionDate);
639-
if (customData != null)
640-
restRequest.WithCustomData(customData);
641-
result = new System.IO.MemoryStream(restRequest.AsByteArray().Result);
642-
}
643-
catch(AggregateException ae)
644-
{
645-
throw ae.Flatten();
646-
}
647-
648-
return result;
649-
}
650433
/// <summary>
651434
/// Delete labeled data.
652435
///
@@ -675,6 +458,7 @@ public BaseModel DeleteUserData(string customerId, Dictionary<string, object> cu
675458
IClient client;
676459
if(_tokenManager == null)
677460
{
461+
client = this.Client;
678462
}
679463
else
680464
{

0 commit comments

Comments
 (0)