def test_vision_recognize(self):
     vr = VisionRecognizer()
     labels = vr.recognize("http://visual-recognition-demo.mybluemix.net/images/73388.jpg")
     self.assertTrue(len(labels) > 0)
     print(labels)
     vlabels = vr.recognize("http://visual-recognition-demo.mybluemix.net/images/73388.jpg", "Animal")
     print(vlabels)
     self.assertTrue(len(labels[0]) > len(vlabels[0]))
    def test_get_images(self):
        vr = VisionRecognizer()
        urls = ["http://visual-recognition-demo.mybluemix.net/images/73388.jpg",
                "http://visual-recognition-demo.mybluemix.net/images/67528.jpg"]

        fname, image = vr._get_images(urls, "imageFile.jpg")
        self.assertTrue("imageFile.zip", fname)
        self.assertTrue(isinstance(image, bytes))
示例#3
0
def rekognize(image_url):
    vr = VisionRecognizer()
    result = vr.recognize(image_url)
    tag_and_score = {}
    if "images" in result:
        labels = result["images"][0]["labels"]
        for lb in labels:
            tag_and_score[lb["label_name"]] = lb["label_score"]

    return tag_and_score
示例#4
0
    def test_get_images(self):
        vr = VisionRecognizer()
        urls = [
            "http://visual-recognition-demo.mybluemix.net/images/73388.jpg",
            "http://visual-recognition-demo.mybluemix.net/images/67528.jpg"
        ]

        fname, image = vr._get_images(urls, "imageFile.jpg")
        self.assertTrue("imageFile.zip", fname)
        self.assertTrue(isinstance(image, bytes))
示例#5
0
 def test_vision_recognize(self):
     vr = VisionRecognizer()
     labels = vr.recognize(
         "http://visual-recognition-demo.mybluemix.net/images/73388.jpg")
     self.assertTrue(len(labels) > 0)
     print(labels)
     vlabels = vr.recognize(
         "http://visual-recognition-demo.mybluemix.net/images/73388.jpg",
         "Animal")
     print(vlabels)
     self.assertTrue(len(labels[0]) > len(vlabels[0]))
def photo2mood(image_urls):
    vr = VisionRecognizer()
    photo_to_mood = MachineLoader.load(machines.photo_mood)
    TARGET_LABELS = ['Boat', 'Human', 'Insect', 'Invertebrate', 'Mammal', 'Man Made Scene', 'Outdoors', 'People Activity', 'Placental Mammal', 'Vertebrate']
    moods = Counter()
    matrix = vr.recognize(image_urls).to_matrix(TARGET_LABELS)
    for r in matrix:
        mood = photo_to_mood.predict(r)[0]
        moods[int(mood)] += 1

    target_mood = moods.most_common(1)[0][0]  # get top and its score
    target_mood = Echonest.MOOD[target_mood]

    return target_mood
    def test_vision_recognize_multi(self):
        vr = VisionRecognizer()
        urls = ["http://visual-recognition-demo.mybluemix.net/images/73388.jpg",
                "http://visual-recognition-demo.mybluemix.net/images/67528.jpg"]

        result = vr.recognize(urls)
        self.assertEqual(len(urls), len(result))

        targets = ["Windmill", "Auto Racing"]
        matrix = result.to_matrix(targets)
        self.assertEqual(result[0]["Windmill"], matrix[0][0])
        self.assertEqual(result[1]["Auto Racing"], matrix[1][1])
        self.assertEqual(0, matrix[0][1])
        self.assertEqual(0, matrix[1][0])
示例#8
0
    def test_vision_recognize_multi(self):
        vr = VisionRecognizer()
        urls = [
            "http://visual-recognition-demo.mybluemix.net/images/73388.jpg",
            "http://visual-recognition-demo.mybluemix.net/images/67528.jpg"
        ]

        result = vr.recognize(urls)
        self.assertEqual(len(urls), len(result))

        targets = ["Windmill", "Auto Racing"]
        matrix = result.to_matrix(targets)
        self.assertEqual(result[0]["Windmill"], matrix[0][0])
        self.assertEqual(result[1]["Auto Racing"], matrix[1][1])
        self.assertEqual(0, matrix[0][1])
        self.assertEqual(0, matrix[1][0])
示例#9
0
def photo2mood(image_urls):
    vr = VisionRecognizer()
    photo_to_mood = MachineLoader.load(machines.photo_mood)
    TARGET_LABELS = [
        'Boat', 'Human', 'Insect', 'Invertebrate', 'Mammal', 'Man Made Scene',
        'Outdoors', 'People Activity', 'Placental Mammal', 'Vertebrate'
    ]
    moods = Counter()
    matrix = vr.recognize(image_urls).to_matrix(TARGET_LABELS)
    for r in matrix:
        mood = photo_to_mood.predict(r)[0]
        moods[int(mood)] += 1

    target_mood = moods.most_common(1)[0][0]  # get top and its score
    target_mood = Echonest.MOOD[target_mood]

    return target_mood
示例#10
0
 def test_get_labels(self):
     vr = VisionRecognizer()
     labels = vr.get_labels("Vehicle")
     self.assertTrue(len(labels) > 0)
     print(labels)
 def test_get_labels(self):
     vr = VisionRecognizer()
     labels = vr.get_labels("Vehicle")
     self.assertTrue(len(labels) > 0)
     print(labels)