src/Classificationbox.Net/ServiceWrapper.cs
/// <summary>
/// Requests the teaching of an image in the given class of the specified model.
/// </summary>
/// <param name="model_id">id of the model to use</param>
/// <param name="className">class this image belongs to</param>
/// <param name="filename">filename of the image</param>
/// <returns>OK for success, otherwise error message</returns>
Requests the teaching of an image in the given class of the specified model.
Requests the teaching of an image in the given class of the specified model .
public string TeachModel(string model_id, string className, string filename)
        {
            Byte[] bytes = File.ReadAllBytes(filename);
            String base64 = Convert.ToBase64String(bytes);
            using (HttpClient client = new HttpClient())
            {
                var payload = string.Format("{{ \"class\": \"{0}\", \"inputs\": [ {{ \"key\": \"image\", \"type\": \"image_base64\", \"value\": \"{1}\"}} ] }}", className, base64);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");
                var request = new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    RequestUri = new Uri(string.Format("{0}/classificationbox/models/{1}/teach", _baseUrl, model_id)),
                    Headers = {
                    { HttpRequestHeader.Accept.ToString(), "application/json; charset=utf-8" }
                },
                    Content = content
                };
                HttpResponseMessage rsp;
                try
                {
                    rsp = client.SendAsync(request).GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
                if (rsp.IsSuccessStatusCode)
                {
                    var s = rsp.Content.ReadAsStringAsync().Result;
                    dynamic json = JObject.Parse(s);
                    if (!json.success.Value) return json;
                    return "OK";
                }
                else
                {
                    var s = rsp.Content.ReadAsStringAsync().Result;
                    return s;
                }
            }
        }
public string TeachModel ( string model_id , string className , string filename ) { Byte [ ] bytes = File . ReadAllBytes ( filename ) ; String base64 = Convert . ToBase64String ( bytes ) ; using ( HttpClient client = new HttpClient ( ) ) { var payload = string . Format ( " \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" " , className , base64 ) ; HttpContent content = new StringContent ( payload , Encoding . UTF8 , " " ) ; var request = new HttpRequestMessage { Method = HttpMethod . Post , RequestUri = new Uri ( string . Format ( " " , _baseUrl , model_id ) ) , Headers = { { HttpRequestHeader . Accept . ToString ( ) , " " } } , Content = content } ; HttpResponseMessage rsp ; try { rsp = client . SendAsync ( request ) . GetAwaiter ( ) . GetResult ( ) ; } catch ( Exception ex ) { return ex . Message ; } if ( rsp . IsSuccessStatusCode ) { var s = rsp . Content . ReadAsStringAsync ( ) . Result ; dynamic json = JObject . Parse ( s ) ; if ( ! json . success . Value ) return json ; return " " ; } else { var s = rsp . Content . ReadAsStringAsync ( ) . Result ; return s ; } } }
Requests the teaching of an image in the given class of the specified model.
Requests the teaching of an image in the given class of the specified model .
OK for success, otherwise error message
OK for success otherwise error message
model_id
string
id of the model to use
id of the model to use
className
string
class this image belongs to
class this image belongs to
filename
string
filename of the image
filename of the image