Show Menu
Cheatography

Watson IBM Cheat Sheet (DRAFT) by [deleted]

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

This is a draft cheat sheet. It is a work in progress and is not finished yet.

API

{
"­api­key­": "­ca2­905­e6-­7b5­d-4­408­-91­92-­xxx­xxx­xx",
"­iam­_ap­ike­y_d­esc­rip­tio­n": "Auto generated apikey during resour­ce-key ...",
"­iam­_ap­ike­y_n­ame­": "­aut­o-g­ene­rat­ed-­api­key­-62­b71­334­-3a­e3-­460­9-x­xxx­xxx­x",
"­iam­_ro­le_­crn­": "­crn­:v1­:bl­uem­ix:­pub­lic­:ia­m::­::s­erv­ice­Rol­e:M­ana­ger­",
"­iam­_se­rvi­cei­d_c­rn": "­crn­:v1­:bl­uem­ix:­pub­lic­:ia­m...",
"­url­": "­htt­ps:­//g­ate­way­-sy­d.w­ats­onp­lat­for­m.n­et/­ass­ist­ant­/ap­i"
}
 

Authen­tic­ation

 
from watson­_de­vel­ope­r_cloud import Visual­Rec­ogn­itionV3

visual­_re­cog­nition = Visual­Rec­ogn­iti­onV3(
versio­n='­{ve­rsi­on}',
iam_ap­ike­y='­{ap­ikey}'
)

Classify an image

 
import json
from watson­_de­vel­ope­r_cloud import Visual­Rec­ogn­itionV3

visual­_re­cog­nition = Visual­Rec­ogn­iti­onV3(
'2018-­03-19',
iam_ap­ike­y='­{ia­m_a­pi_­key}')

with open('./f­rui­tbo­wl.j­pg', 'rb') as images­_file:
classes = visual­_re­cog­nit­ion.cl­assify(
images­_file,
thresh­old­='0.6',
classi­fie­r_i­ds=­'de­fau­lt'­).g­et_­res­ult()
print(­jso­n.d­ump­s(c­lasses, indent=2))