Esempio n. 1
0
def predict_likeliness(classifier, sess, default_graph, filename):
    img = person_detector.get_person(filename, sess, default_graph)
    img = img.convert('L')
    img.save(filename, "jpeg")
    certainty = classifier.classify(filename)
    pos = certainty["positive"]
    return pos
Esempio n. 2
0
def predict_likeliness(classifier, sess, p, default_graph):
    ratings = []
    images = p['images']
    for image in images:
        req = requests.get(image)
        tmp_filename = f"images/tmp/run.jpg"
        if req.status_code == 200:
            with open(tmp_filename, "wb") as f:
                f.write(req.content)

        #multiprocessing.Process(target=person_detector.get_person, args(tmp_filename, sess))
        img = person_detector.get_person(tmp_filename, sess, default_graph)
        if img:
            img = img.convert('L')
            img.save(tmp_filename, "jpeg")
            certainty = classifier.classify(tmp_filename)
            pos = certainty["positive"]
            ratings.append(pos)
    ratings.sort(reverse=True)
    ratings = ratings[:5]
    if len(ratings) == 0:
        return 0.001

    try:
        return ratings[0] * 0.6 + sum(ratings[1:]) / len(ratings[1:]) * 0.4
    except ZeroDivisionError:
        return ratings[0] * 0.6
Esempio n. 3
0
    def predict_likeliness(self, classifier, sess):

        ratings = []
        if not len(self.images):
            print('no image')
            return 0.01, None
        for image in self.images:
            req = requests.get(image, stream=True)
            tmp_filename = f"./images/tmp/run.jpg"
            if req.status_code == 200:
                with open(tmp_filename, "wb") as f:
                    f.write(req.content)
            img = person_detector.get_person(tmp_filename, sess)
            if img != None:
                img = img.convert('L')
                img.save(tmp_filename, "jpeg")
                certainty = classifier.classify(tmp_filename)
                pos = certainty["positive"]
                ratings.append(pos)
        if len(ratings) == 0:
            print('person detector failed')
            return 0.02, None
        if len(ratings) == 1:
            # print('len(ratings) = 1')
            return max(ratings[0], 0.03), 0
        best_pic_id = np.argmin(ratings)
        ratings.sort(reverse=True)
        if len(ratings) > 1:
            ratings = ratings[:3]
            return max(
                ratings[0] * 0.6 + sum(ratings[1:]) / len(ratings[1:]) * 0.4,
                0.04), best_pic_id
Esempio n. 4
0
 def predict_likeliness(self, classifier, sess):
     ratings = []
     for image in self.images:
         req = requests.get(image, stream=True)
         tmp_filename = f"./images/tmp/run.jpg"
         if req.status_code == 200:
             with open(tmp_filename, "wb") as f:
                 f.write(req.content)
         img = person_detector.get_person(tmp_filename, sess)
         if img:
             img = img.convert('L')
             img.save(tmp_filename, "jpeg")
             certainty = classifier.classify(tmp_filename)
             pos = certainty["positive"]
             ratings.append(pos)
     ratings.sort(reverse=True)
     ratings = ratings[:5]
     if len(ratings) == 0:
         return 0.001
     return ratings[0] * 0.6 + sum(ratings[1:]) / len(ratings[1:]) * 0.4
Esempio n. 5
0
    images = [f for f in os.listdir(IMAGE_FOLDER) if os.path.isfile(os.path.join(IMAGE_FOLDER, f))]
    positive_images = filter(lambda image: (image.startswith("1_")), images)
    negative_images = filter(lambda image: (image.startswith("0_")), images)
    lovoo_images = [f for f in os.listdir(LOVOO_FOLDER) if os.path.isfile(os.path.join(LOVOO_FOLDER, f))]

    with detection_graph.as_default():
        with tf.Session() as sess:

            for pos in lovoo_images:
                old_filename = LOVOO_FOLDER + "/" + pos
                new_filename = POS_FOLDER + "/" + pos[:-5] + ".jpg"

                if not os.path.isfile(new_filename):
                    print(">> Moving positive image: " + pos)
                    img = person_detector.get_person(old_filename, sess)
                    if not img:
                        continue
                    img = img.convert('L')
                    img.save(new_filename, "jpeg")


            for pos in positive_images:
                old_filename = IMAGE_FOLDER + "/" + pos
                new_filename = POS_FOLDER + "/" + pos[:-5] + ".jpg"

                if not os.path.isfile(new_filename):
                    print(">> Moving positive image: " + pos)
                    img = person_detector.get_person(old_filename, sess)
                    if not img:
                        continue