무지개 이미지가 있고 Google Vision API를 사용 score
하여 사용자 지정 레이블 집합 을 예측 한다고 가정 합니다. 예를 들면 다음과 같습니다.
0 Rainbow: 0.965621
1 Sky 0.887454
2 Artwork 0.813930
3 Giraffe 0.015654
4 Coffee 0.012483
다음 Google Vision API 코드 :
def detect_labels(path):
"""Detects labels in the file."""
from google.cloud import vision
import io
client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description, label.score, label.mid)
다음 레이블 및 점수 값을 반환합니다.
description score mid
0 Rainbow 0.965621 /m/0b48hv
1 Vertebrate 0.924276 /m/09686
2 White 0.921867 /m/083jv
3 Cartoon 0.918200 /m/0215n
4 Product 0.908071 /m/01jwgf
5 Green 0.907698 /m/038hg
6 Organism 0.875143 /m/05nnm
7 Textile 0.873498 /m/0dnr7
8 Rectangle 0.853343 /m/0j62f
9 Font 0.841818 /m/03gq5hm
단지 '톱 10'라벨이 반환되어 있기 때문에, 나는이없는 score
등의 라벨을 'Coffee'
하고 'Giraffe'
.
10 개 이상의 라벨을 반환 할 수 있습니까? 아니면 이것이 Google Vision API의 제한 사항입니까?
상위 10 개 라벨을 반환하는 대신 Google Vision API를 사용하여 사용자 지정 라벨의 가능성을 예측할 수 있나요? 예를 들어,의 가능성 'Coffee'
은 0.012483
?
모든 레이블 descriptions
과 mid
값 에 액세스 할 수 있습니까? 에 따르면 EntityAnnotation , mid
그러나 그것은 어떤 값에서 분명히 사용할 수 있는지 상태,에 '불투명'엔티티 ID입니다 Google 지식 그래프 검색 API . 이 문맥에서 '불투명'이란 Google이 전체 라벨 목록을 공유하지 않는다는 의미인가요?
내 AutoML Vision 모델을 학습시키고 내 라벨을 정의 할 수 있다는 것을 이해 하지만 Google의 기존 라벨 분류를 사용하는 것이 기쁘기 때문에이 작업을하는 것은 어리석은 것 같습니다. 레이블 데이터에 더 많이 액세스하고 싶습니다. 주어진 이미지 score
에 대해 선택한 것을 간단히 요청할 수있는 방법이 mid
있습니까?
참고 : Google API를 통해 필요한 데이터에 액세스 할 수없는 경우 대체 API를 탐색하게되어 기쁩니다.
질문에 답하려면 :
max_results
요청을 조정하면 됩니다.나는 batch_annotate_images () 를 사용하고 사용할 탐지 유형을 정의 하기 위해 요청 을 사용하는 Vision API 사용에 대해 다른 접근 방식을 수행했습니다 . 이 접근 방식을 사용하면 이미지 처리에 사용할 기능 을 쉽게 제어 할 수 있습니다 .
def detect_labels(path):
"""Detects labels in the file."""
from google.cloud import vision
import io
client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
features = [{"type_": vision.Feature.Type.LABEL_DETECTION, "max_results": 11}]
requests = [{"image": image, "features": features}]
response = client.batch_annotate_images(requests=requests)
for image_response in response.responses:
for label in image_response.label_annotations:
print(u"description : {}".format(label.description))
print(u"score : {}".format(label.score))
print(u"mid : {}\n".format(label.mid))
이 이미지를 테스트에 사용 하고 max_results 값을 3과 11로 변경했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다