Skip to content

Instantly share code, notes, and snippets.

@jashmenn
Forked from fairchild/annotation.json
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jashmenn/ddc0ace3448e73be886a to your computer and use it in GitHub Desktop.
Save jashmenn/ddc0ace3448e73be886a to your computer and use it in GitHub Desktop.
a = {
"annotations" => [
{
"x" => 19,
"y" => 20,
"w" => 50,
"h" => 50,
"predictions" => {
"green" => 0.2,
"red" => 0.95
}
}
]}
def hstorify_annotation(annotation)
annotation.inject({}) do |acc, (k,v)|
acc[k] = v if ["x", "y", "w", "h"].include?(k)
if k == "predictions"
v.each do |(pred_k, pred_v)|
acc[pred_k + "_prediction"] = pred_v
end
end
acc
end
end
annotations = a["annotations"].collect{|a| hstorify_annotation(a)}
pp annotations
# =>
[{"x"=>19,
"y"=>20,
"w"=>50,
"h"=>50,
"green_prediction"=>0.2,
"red_prediction"=>0.95}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment