Пример #1
0
    def test_send_age_feedback(self):
        """ send face feedback """

        feedback_info = FeedbackInfo(end_user_id='robert_python_test_key',
                                     session_id='from_your_browser',
                                     event_type='annotation',
                                     output_id='oooooooid')

        m = self.app.models.get('general-v1.3')

        identities = [
            Concept(concept_id='xx', value=True),
            Concept(concept_id='x2', value=False)
        ]
        ages = [Concept(concept_id='1', value=True)]
        face = Face(identity=FaceIdentity(identities),
                    age_appearance=FaceAgeAppearance(ages))

        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8)), face=face)
        ]

        ret = m.send_region_feedback(
            input_id='xyz',
            url='https://samples.clarifai.com/dog.tiff',
            regions=regions,
            feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)

        # send multiple items
        identities = [
            Concept(concept_id='xx', value=True),
            Concept(concept_id='x2', value=False),
            Concept(concept_id='x4', value=True)
        ]
        ages = [
            Concept(concept_id='1', value=True),
            Concept(concept_id='2', value=False)
        ]
        face = Face(identity=FaceIdentity(identities),
                    age_appearance=FaceAgeAppearance(ages))

        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8)), face=face)
        ]

        ret = m.send_region_feedback(
            input_id='xyz',
            url='https://samples.clarifai.com/dog.tiff',
            regions=regions,
            feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)
Пример #2
0
  def test_send_complete_multicultural_feedback(self):
    """ send face feedback """

    feedback_info = FeedbackInfo(
        end_user_id='robert_python_test_key',
        session_id='from_your_browser',
        event_type='annotation',
        output_id='oooooooid')

    m = self.app.models.get('general-v1.3')

    identities = [Concept(concept_id='xx', value=True), Concept(concept_id='x2', value=False)]
    ages = [Concept(concept_id='1', value=True), Concept(concept_id='2', value=False)]
    genders = [Concept(concept_id='male', value=True), Concept(concept_id='female', value=False)]
    cultures = [
        Concept(concept_id='american', value=True),
        Concept(concept_id='asian', value=False)
    ]

    face = Face(
        identity=FaceIdentity(identities),
        age_appearance=FaceAgeAppearance(ages),
        gender_appearance=FaceGenderAppearance(genders),
        multicultural_appearance=FaceMulticulturalAppearance(cultures))

    regions = [Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8)), face=face)]

    ret = m.send_region_feedback(
        input_id='xyz',
        url=sample_inputs.DOG_TIFF_IMAGE_URL,
        regions=regions,
        feedback_info=feedback_info)
    self.assertEqual(ret['status']['code'], 10000)
Пример #3
0
    def test_send_gender_feedback(self):
        """ send face feedback """

        feedback_info = FeedbackInfo(end_user_id='robert_python_test_key',
                                     session_id='from_your_browser',
                                     event_type='annotation',
                                     output_id='oooooooid')

        m = self.app.models.get(model_id=GENERAL_MODEL_ID)

        identities = [
            Concept(concept_id='xx', value=True),
            Concept(concept_id='x2', value=False)
        ]
        genders = [
            Concept(concept_id='male', value=True),
            Concept(concept_id='female', value=False)
        ]
        face = Face(identity=FaceIdentity(identities),
                    gender_appearance=FaceGenderAppearance(genders))

        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8)), face=face)
        ]

        ret = m.send_region_feedback(input_id='xyz',
                                     url=sample_inputs.DOG_TIFF_IMAGE_URL,
                                     regions=regions,
                                     feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)
Пример #4
0
    def test_send_region_feedback(self):
        """ send region feedback with concepts """

        feedback_info = FeedbackInfo(end_user_id='robert_python_test_key',
                                     session_id='from_your_browser',
                                     event_type='annotation',
                                     output_id='oooooooid')

        m = self.app.models.get('general-v1.3')

        concepts = [Concept(concept_id='ab', value=False)]
        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8),
                              feedback_type='accurate'),
                   concepts=concepts)
        ]

        ret = m.send_region_feedback(
            input_id='xyz',
            url='https://samples.clarifai.com/dog.tiff',
            concepts=['matid2'],
            not_concepts=['lambo'],
            regions=regions,
            feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)

        concepts = [
            Concept(concept_id='ab', value=False),
            Concept(concept_id='bb', value=True)
        ]
        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8)),
                   concepts=concepts),
            Region(RegionInfo(bbox=BoundingBox(0.1, 0.2, 0.8, 0.85)),
                   concepts=concepts)
        ]

        ret = m.send_region_feedback(
            input_id='xyz',
            url='https://samples.clarifai.com/dog.tiff',
            concepts=['matid2'],
            not_concepts=['lambo'],
            regions=regions,
            feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)
Пример #5
0
    def test_send_region_feedback(self):
        """ send region feedback with concepts """

        feedback_info = FeedbackInfo(end_user_id='robert_python_test_key',
                                     session_id='from_your_browser',
                                     event_type='annotation',
                                     output_id='oooooooid')

        m = self.app.models.get(model_id=GENERAL_MODEL_ID)

        concepts = [Concept(concept_id='ab', value=False)]
        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8),
                              feedback_type='accurate'),
                   concepts=concepts)
        ]

        ret = m.send_region_feedback(input_id='xyz',
                                     url=sample_inputs.DOG_TIFF_IMAGE_URL,
                                     concepts=['matid2'],
                                     not_concepts=['lambo'],
                                     regions=regions,
                                     feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)

        concepts = [
            Concept(concept_id='ab', value=False),
            Concept(concept_id='bb', value=True)
        ]
        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8)),
                   concepts=concepts),
            Region(RegionInfo(bbox=BoundingBox(0.1, 0.2, 0.8, 0.85)),
                   concepts=concepts)
        ]

        ret = m.send_region_feedback(input_id='xyz',
                                     url=sample_inputs.DOG_TIFF_IMAGE_URL,
                                     concepts=['matid2'],
                                     not_concepts=['lambo'],
                                     regions=regions,
                                     feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)
Пример #6
0
    def test_send_different_region_feedbacks_with_enum_vars(self):
        """ send different kind of region feedbacks with enums
        - accurate
        - misplaced
        - not_detected
        - false_positive
    """
        feedback_info = FeedbackInfo(end_user_id='robert_python_test_key',
                                     session_id='from_your_browser',
                                     event_type='annotation',
                                     output_id='oooooooid')

        m = self.app.models.get('general-v1.3')

        # positive
        concepts = [Concept(concept_id='ab', value=False)]
        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8),
                              feedback_type=FeedbackType.accurate),
                   concepts=concepts)
        ]

        ret = m.send_region_feedback(
            input_id='xyz',
            url='https://samples.clarifai.com/dog.tiff',
            concepts=['matid2'],
            not_concepts=['lambo'],
            regions=regions,
            feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)

        # misplaced
        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.8, 0.9),
                              feedback_type=FeedbackType.misplaced),
                   concepts=concepts)
        ]

        ret = m.send_region_feedback(
            input_id='xyz',
            url='https://samples.clarifai.com/dog.tiff',
            concepts=['matid2'],
            not_concepts=['lambo'],
            regions=regions,
            feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)

        # misplaced
        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.1, 0.2, 0.4, 0.5),
                              feedback_type=FeedbackType.not_detected),
                   concepts=concepts)
        ]

        ret = m.send_region_feedback(
            input_id='xyz',
            url='https://samples.clarifai.com/dog.tiff',
            concepts=['matid2'],
            not_concepts=['lambo'],
            regions=regions,
            feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)

        # false_positive
        regions = [
            Region(RegionInfo(bbox=BoundingBox(0.1, 0.2, 0.4, 0.5),
                              feedback_type=FeedbackType.false_positive),
                   concepts=concepts)
        ]

        ret = m.send_region_feedback(
            input_id='xyz',
            url='https://samples.clarifai.com/dog.tiff',
            concepts=['matid2'],
            not_concepts=['lambo'],
            regions=regions,
            feedback_info=feedback_info)
        self.assertEqual(ret['status']['code'], 10000)
Пример #7
0
def test_bulk_update_with_regions(mock_http_client):  # type: (mock.Mock) -> None
  mock_execute_request = mock_request(
      mock_http_client, """
{
  "status": {
    "code": 10000,
    "description": "Ok"
  },
  "inputs": [
    {
      "id": "@inputID",
      "data": {
        "image": {
          "url": "@imageURL"
        },
        "concepts": [
          {
            "id": "@concept1",
            "name": "@concept1",
            "value": 1,
            "app_id": "@appID"
          },
          {
            "id": "@concept2",
            "name": "@concept2",
            "value": 0,
            "app_id": "@appID"
          }
        ]
      },
      "created_at": "2019-01-29T15:23:21.188492Z",
      "modified_at": "2019-01-29T15:23:21.575667Z",
      "status": {
        "code": 30200,
        "description": "Input image modification success"
      }
    }
  ]
}
""")

  app = ClarifaiApp()
  images = app.inputs.bulk_update(
      [
          Image(
              image_id='@inputID',
              regions=[
                  Region(
                      region_info=RegionInfo(
                          bbox=BoundingBox(0.5, 0.5, 1.0, 1.0),
                          feedback_type=FeedbackType.misplaced),
                      concepts=[
                          Concept(concept_id='@concept1', value=True),
                          Concept(concept_id='@concept2', value=False)
                      ],
                      region_id='@regionID',
                      face=Face(
                          identity=FaceIdentity(concepts=[
                              Concept(concept_id='@faceConcept1', value=True),
                              Concept(concept_id='@faceConcept2', value=False),
                          ])))
              ])
      ],
      action='overwrite')

  assert images[0].input_id == '@inputID'
  assert images[0].url == '@imageURL'
  assert images[0].status.code == 30200

  assert_request(
      mock_execute_request, 'PATCH', '/v2/inputs', """
{
  "inputs": [
    {
      "id": "@inputID",
      "data": {
        "regions": [
          {
            "id": "@regionID",
            "region_info": {
              "bounding_box": {
                "top_row": 0.5,
                "left_col": 0.5,
                "bottom_row": 1,
                "right_col": 1
              },
              "feedback": "misplaced"
            },
            "data": {
              "concepts": [
                {
                  "id": "@concept1",
                  "value": 1
                },
                {
                  "id": "@concept2",
                  "value": 0
                }
              ],
              "face": {
                "identity": {
                  "concepts": [
                    {
                      "id": "@faceConcept1",
                      "value": 1
                    },
                    {
                      "id": "@faceConcept2",
                      "value": 0
                    }
                  ]
                }
              }
            }
          }
        ]
      }
    }
  ],
  "action": "overwrite"
}
        """)
Пример #8
0
  def test_send_different_region_feedbacks(self):
    """ send different kind of region feedbacks
        - accurate
        - misplaced
        - not_detected
        - false_positive
    """
    feedback_info = FeedbackInfo(
        end_user_id='robert_python_test_key',
        session_id='from_your_browser',
        event_type='annotation',
        output_id='oooooooid')

    m = self.app.models.get('general-v1.3')

    # positive
    concepts = [Concept(concept_id='ab', value=False)]
    regions = [
        Region(
            RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.7, 0.8), feedback_type='accurate'),
            concepts=concepts)
    ]

    ret = m.send_region_feedback(
        input_id='xyz',
        url=sample_inputs.DOG_TIFF_IMAGE_URL,
        concepts=['matid2'],
        not_concepts=['lambo'],
        regions=regions,
        feedback_info=feedback_info)
    self.assertEqual(ret['status']['code'], 10000)

    # misplaced
    regions = [
        Region(
            RegionInfo(bbox=BoundingBox(0.3, 0.2, 0.8, 0.9), feedback_type='misplaced'),
            concepts=concepts)
    ]

    ret = m.send_region_feedback(
        input_id='xyz',
        url=sample_inputs.DOG_TIFF_IMAGE_URL,
        concepts=['matid2'],
        not_concepts=['lambo'],
        regions=regions,
        feedback_info=feedback_info)
    self.assertEqual(ret['status']['code'], 10000)

    # misplaced
    regions = [
        Region(
            RegionInfo(bbox=BoundingBox(0.1, 0.2, 0.4, 0.5), feedback_type='not_detected'),
            concepts=concepts)
    ]

    ret = m.send_region_feedback(
        input_id='xyz',
        url=sample_inputs.DOG_TIFF_IMAGE_URL,
        concepts=['matid2'],
        not_concepts=['lambo'],
        regions=regions,
        feedback_info=feedback_info)
    self.assertEqual(ret['status']['code'], 10000)

    # false_positive
    regions = [
        Region(
            RegionInfo(bbox=BoundingBox(0.1, 0.2, 0.4, 0.5), feedback_type='false_positive'),
            concepts=concepts)
    ]

    ret = m.send_region_feedback(
        input_id='xyz',
        url=sample_inputs.DOG_TIFF_IMAGE_URL,
        concepts=['matid2'],
        not_concepts=['lambo'],
        regions=regions,
        feedback_info=feedback_info)
    self.assertEqual(ret['status']['code'], 10000)