Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1.  
  2. final List<ClarifaiOutput<Concept>> predictionResults2 = // Concept zamieniony na prediction
  3. client.getDefaultModels().generalModel()//.predict("kulak")//getModelByID("kulak") //getDefaultModels().generalModel() // You can also do client.getModelByID("id") to get custom models
  4. .predict()
  5. .withInputs(
  6. ClarifaiInput.forImage(ClarifaiImage.of("http://pre01.deviantart.net/6be4/th/pre/i/2012/001/6/1/girl_with_the_glasses_by_suannystock-d4kx0l4.jpg"))
  7. )
  8. .executeSync()
  9. .get();
  10.  
  11.  
  12. HashMap<String,Double> map_tag = new HashMap<String,Double>();
  13. for (Concept temp : predictionResults2.get(0).data()) {
  14. if(temp.value() > 0.92)
  15. {
  16. if(temp.name().equals("eyeglasses"))
  17. map_tag.put("glasses",(double) temp.value());
  18. if(temp.name().equals("eyewear"))
  19. map_tag.put("glasses",(double) temp.value());
  20. else if(temp.name().equals("woman"))
  21. map_tag.put("female",(double) temp.value());
  22. else if(temp.name().equals("child"))
  23. map_tag.put("teen",(double) temp.value());
  24. else if(temp.name().equals("man"))
  25. map_tag.put("male",(double) temp.value());
  26. else if(temp.name().equals("business"))
  27. map_tag.put("garnitur",(double) temp.value());
  28. else if(temp.name().equals("tie"))
  29. map_tag.put("tie",(double) temp.value());
  30. else if(temp.name().equals("cap"))
  31. map_tag.put("czapka_daszek",(double) temp.value());
  32. else if(temp.name().equals("fashion"))
  33. map_tag.put("fashion",(double) temp.value());
  34.  
  35. }
  36. }
  37.  
  38.  
  39. // najpierw custom model
  40.  
  41. for (Prediction temp : predictionResults.get(0).data())
  42. {
  43.  
  44. if(temp.asConcept().value() > 0.60)
  45. { //System.out.println(temp.asConcept().name());
  46. if(temp.asConcept().name().equals("female") && !map_tag.containsKey("male") ) // tag to female, sprawdz czy nie dodalismy juz male bo ma wieksze prawdopodobienstwo
  47. map_tag.put("female",(double) temp.asConcept().value());
  48. else if(temp.asConcept().name().equals("male") && !map_tag.containsKey("female") ) // tag to male, sprawdz czy nie dodalismy juz male bo ma wieksze prawdopodobienstwo
  49. map_tag.put("male",(double) temp.asConcept().value());
  50. else if(temp.asConcept().name().equals("middle") && !map_tag.containsKey("old") && !map_tag.containsKey("teen")) // tag to female, sprawdz czy nie dodalismy juz male bo ma wieksze prawdopodobienstwo
  51. map_tag.put("middle",(double) temp.asConcept().value());
  52. else if(temp.asConcept().name().equals("teen") && !map_tag.containsKey("old") && !map_tag.containsKey("middle") ) // tag to female, sprawdz czy nie dodalismy juz male bo ma wieksze prawdopodobienstwo
  53. map_tag.put("teen",(double) temp.asConcept().value());
  54. else if(temp.asConcept().name().equals("old") && !map_tag.containsKey("teen") && !map_tag.containsKey("middle") ) // tag to female, sprawdz czy nie dodalismy juz male bo ma wieksze prawdopodobienstwo
  55. map_tag.put("old",(double) temp.asConcept().value());
  56. else if(temp.asConcept().name().equals("garnitur"))
  57. map_tag.put("suit",(double) temp.asConcept().value());
  58. else // jak nie jest z zadnej grupy np. wiek, plec, i ma > 60.0 pewnosc to dodajemy
  59. map_tag.put(temp.asConcept().name(),(double) temp.asConcept().value());
  60. }
  61. }
  62.  
  63. System.out.println("Przekazane tagi: ");
  64. for (String temp : map_tag.keySet()) {
  65. System.out.println(temp);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement