Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Example of calling clarifai python API through R via reticulate
  • Loading branch information
longhowlam committed Mar 15, 2017
1 parent 64437e5 commit 46c4b8a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ExampleClarifaiCalls.R
@@ -0,0 +1,47 @@
###############################################################################
##
## Image recognition using clarifai
## make sure to install the python module from clarifai,
## see https://github.com/Clarifai/clarifai-python for instructions

library(reticulate)
library(listviewer)

#### import the clarifai module

cf = import("clarifai")
clf_app = cf$rest$ClarifaiApp()

############ call the general computer vision model of clarifai ###############

outclarify = clf_app$tag_urls(
list('https://samples.clarifai.com/metro-north.jpg')
)

### the output of the clarifai app is a nested list, which can be quite
### intimidating the listviewer package is handy to view these nested lists

listviewer::jsonedit(outclarify)

############# Not safe for work model #########################################

outclarify = clf_app$tag_urls(
list('https://www.persellshop.nl/images/detailed/2/73416_C.jpg'),
model='nsfw-v1.0'
)

########### the celebrity model (alpha) ######################################

### define the model
celeb_model = clf_app$models$get('e466caa0619f444ab97497640cefc4dc')

### create image objects
img1 = cf$rest$Image(url = "https://samples.clarifai.com/celebrity.jpeg")
img2 = cf$rest$Image(url = "http://ll-media.tmz.com/2006/09/29/pitt2-1.jpg")

celeb_out = celeb_model$predict(list(img1, img2))
jsonedit(celeb_out)




0 comments on commit 46c4b8a

Please sign in to comment.