Page 26 - MSDN Magazine, May 2017
P. 26

Figure 3 Select Content Moderator from the Cognitive Services List
your results, you and your team gather around your kegerator to celebrate with a fresh beverage. Barely two sips into your micro-brewed IPA, tweets are keeping your phone on constant vibrate. There’s a flood of angry customers: “Why are you blocking my innocent pictures?” “My brother can get pictures with substantially more skin through.
You need to fix this!”
Image classification is good, but there’s no one
size fits all. The bare Content Moderator APIs we just used are clearly able to assist humans to make good decisions, but they’re not perfect. One improvement we could’ve made is to fine-tune the moderation by using the raw scores instead of the true/false adult-and-racy classifications. Additionally, it appears that users tend to use the same images repeatedly. Fortunately, Content Moderator provides a List API to manage a cus- tom set of images or text you’ve already screened. The moderator API does some fuzzy matching against the images, to prevent users from easily fooling it with slight modifications or resizing. This is a nice enhancement over the first approach,
to hook up the Content Moderator API to the Content Moderator review portal later.
The Azure Portal also shows you the endpoint as https://westus.api.cognitive.microsoft.com/contentmoderator. While that’s the correct base address, it’s a little too short. The full end- point is in the Content Moderator documentation.
As shown in Figure 4, we specify “URL” as DataRepresentation to send the URL to the picture, but you can just as easily send the image in a blob. Once you’ve called the moderator API, the body of the returned result contains JSON with the scores for the image. The scores range from 0.0 (innocent) to 1.0 (very adult/racy).
You can see that the result, shown in Figure 5, contains the adult and racy prediction scores and the conclusions about whether it made the threshold in the classified flags. Happy as a clam, you throw these few lines of code in your bot and block all the content that’s racy or adult. You deploy the new version of the bot to Azure and users stream in again to consult your oracle. Phew. Happy with
Figure 4 Sending a Picture URL to Content Moderator
but it wouldn’t rule out those false positives the help desk had to contend with. As always, the optimal solution is found when humans and machines work as a team on the more difficult cases. Computer Vision can help detect the extremes when images are clearly racy or adult, or clearly not. For the edge cases in between, we as humans can decide on which side of the fence the con- tent falls for our particular scenario. This is where the Content Moderator review tool and API really shine. Let’s look at how we can use it to improve our solution.
Calling the Moderator Review API
The approach up to now has been straightforward: Send a picture and block or allow it based on the Content Moderator labels. Now we’re going to expand the solution. The idea is to set up a flow as shown in Figure 6.
In this scenario, the user first sends an image to the Butterfly bot. In Step 2, the bot’s Web service sends the picture to the Content Mod- erator using the Review API’s Job operation, which takes a workflow Id as a parameter. We’ll set up this workflow in the review tool. Our specific workflow (Step 3) will immediately allow all pictures that are below a certain adult/racy score (for example, 0.7) and flag others that exceed a certain limit (such as 0.9). Our bot will allow the
Figure 5 Adult and Racy Classification Scores for an Image
var unirest = require("unirest");
var url = "https://westus.api.cognitive.microsoft.com/contentmoderator/
moderate/v1.0/ProcessImage/Evaluate";
module.exports = function(input, cb) { unirest.post(url)
.type("json") .headers({
"content-type": "application/json",
"Ocp-Apim-Subscription-Key":<Key from the Azure portal>, })
.send({
"DataRepresentation": "URL", "Value": input
})
.end(function (res) {
return cb(res.error, res.body ); });
};
"AdultClassificationScore":0.0324602909386158, "IsImageAdultClassified":false, "RacyClassificationScore":0.06506475061178207, "IsImageRacyClassified":false, "AdvancedInfo":[],
"Result":false, "Status":{
"Code":3000, "Description":"OK", "Exception":null},
"TrackingId":"WU_ibiza_4470e022-4110-48bb-b4e8-7656b1f6703f_ ContentModerator.F0_3e598d6c-5678-4e24-b7c6-62c40ef42028"
22 msdn magazine
Cognitive Services


































































































   24   25   26   27   28