Created
October 22, 2018 04:06
-
-
Save willcrichton/62c51715b0cf0fdd55b815dbdc126c50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var videos = [{frames: [1,2,3]},{frames: [1,2,3]},{frames: [1,2,3]}] | |
var detectFaceBoundingBoxes = function(frame) { | |
return flip(.5) ? [.7] : (flip(.5) ? [.7, .8] : (flip(.5) ? [.7, .8, .9] : [.7, .8, .9, .7])) | |
} | |
var predictGender = function(boundingBox, frame) { | |
return flip(.7) ? .9 : .1 | |
} | |
var isWolfBlitzer = function(boundingBox, frame) { | |
return flip(.7) ? .8 : .2 | |
} | |
var isPanel = function(boundingBoxes) { | |
return boundingBoxes.length >= 2 | |
} | |
var frameReduce = function(f, frame) { | |
return function(boundingBox) { | |
return f(boundingBox, frame) | |
} | |
} | |
var pHasAny = function(list) { | |
return 1 - reduce(function(cur, total) { return (1 - cur) * total }, 1, list) | |
} | |
// how many panels with Wolf Blitzer also contained at least one woman? | |
var samples = map(function( video ) { | |
var frameProbs = map(function( frame ) { | |
// list where each value is bounding box coordinates with probabilities | |
var boundingBoxes = detectFaceBoundingBoxes(frame) | |
// list where each value is p(woman) for that bounding box | |
var genders = map(frameReduce(predictGender, frame), boundingBoxes) | |
// list where each value is p(wolf) for that bounding box | |
var wolfCounts = map(frameReduce(isWolfBlitzer, frame), boundingBoxes) | |
var hasWoman = pHasAny(genders) // hasWoman is a probability | |
var hasWolf = pHasAny(wolfCounts) // hasWolf is a probability | |
return hasWolf * hasWoman * isPanel(boundingBoxes) | |
}, video.frames) | |
return reduce( function(frameProb, acc) { | |
return frameProb > .5 || acc | |
}, false, frameProbs) | |
}, videos) | |
var num_panels = reduce(function(sample, acc) { return sample + acc}, 0, samples) | |
display(num_panels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment