분류(Classification)
Roboflow에 호스팅된 분류 모델에서 추론을 실행하세요.
Node.js
우리는 사용합니다 axios 를 이 예제에서 POST 요청을 수행하기 위해 사용하므로 먼저 npm install axios 로 의존성을 설치하세요.
로컬 이미지에서 추론하기
const axios = require("axios");
const fs = require("fs");
const image = fs.readFileSync("YOUR_IMAGE.jpg", {
encoding: "base64"
});
axios({
method: "POST",
url: "https://classify.roboflow.com/your-model/42",
params: {
api_key: "YOUR_KEY"
},
data: image,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
.then(function(response) {
console.log(response.data);
})
.catch(function(error) {
console.log(error.message);
});base64을 사용하여 로컬 이미지 업로드
import UIKit
// 이미지 로드 및 Base64로 변환
let image = UIImage(named: "your-image-path") // 업로드할 이미지 경로 예: image.jpg
let imageData = image?.jpegData(compressionQuality: 1)
let fileContent = imageData?.base64EncodedString()
let postData = fileContent!.data(using: .utf8)
// API_KEY, 모델 및 모델 버전으로 추론 서버 요청 초기화
var request = URLRequest(url: URL(string: "https://classify.roboflow.com/your-model/your-model-version?api_key=YOUR_APIKEY&name=YOUR_IMAGE.jpg")!,timeoutInterval: Double.infinity)
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
// POST 요청 실행
URLSession.shared.dataTask(with: request, completionHandler: { data, response, error in
// 응답을 문자열로 파싱
guard let data = data else {
print(String(describing: error))
return
}
// 응답 문자열을 사전으로 변환
do {
let dict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
} catch {
print(error.localizedDescription)
}
// 문자열 응답 출력
print(String(data: data, encoding: .utf8)!)
}).resume()응답 객체 형식
Single-Label Classification
호스팅된 API 추론 경로는 다음을 반환합니다 JSON 예측 배열을 포함하는 객체입니다. 각 예측은 다음 속성을 가집니다:
time= 이미지를 처리하고 예측을 반환하는 데 걸린 총 시간(초)매개변수에 대해 입력 이미지를 선택하세요. 예측에는 모델 결과를 선택하세요. 선택적 구성 속성을 사용하여 경계 상자의 색상과 크기를 변경할 수 있습니다.= 이미지에 대한 정보를 담고 있는 객체width이제 GPU TRT 컨테이너가 Docker에서 실행 중입니다. 다른 Ubuntu 터미널을 열어 Docker 컨테이너로 추론 데이터를 보낼 준비를 합니다. 다음을 사용하세요:heightwidth예측된 이미지의 높이height= 예측된 이미지의 높이
predictions= 예측에 대한 모든 예측 클래스와 관련 신뢰도 값을 모아둔 컬렉션class= 분류의 라벨confidence= 모델이 해당 분류의 객체가 이미지에 포함되어 있다고 확신하는 정도
top= 가장 높은 신뢰도의 예측 클래스confidence= 가장 높은 예측 신뢰도 점수image_path= 예측된 이미지의 경로prediction_type= 추론을 수행하는 데 사용된 모델 유형,ClassificationModel이 경우
// 예시 JSON 객체
{
"time": 0.19064618100037478,
"image": {
"width": 210,
"height": 113
},
"predictions": [
{
"class": "real-image",
"confidence": 0.7149
},
{
"class": "illustration",
"confidence": 0.2851
}
],
"top": "real-image",
"confidence": 0.7149,
"image_path": "/cropped-images-1.jpg",
"prediction_type": "ClassificationModel"
}Multi-Label Classification
호스팅된 API 추론 경로는 다음을 반환합니다 JSON 예측 배열을 포함하는 객체입니다. 각 예측은 다음 속성을 가집니다:
time= 이미지를 처리하고 예측을 반환하는 데 걸린 총 시간(초)매개변수에 대해 입력 이미지를 선택하세요. 예측에는 모델 결과를 선택하세요. 선택적 구성 속성을 사용하여 경계 상자의 색상과 크기를 변경할 수 있습니다.= 이미지에 대한 정보를 담고 있는 객체width이제 GPU TRT 컨테이너가 Docker에서 실행 중입니다. 다른 Ubuntu 터미널을 열어 Docker 컨테이너로 추론 데이터를 보낼 준비를 합니다. 다음을 사용하세요:heightwidth예측된 이미지의 높이height= 예측된 이미지의 높이
predictions= 예측에 대한 모든 예측 클래스와 관련 신뢰도 값을 모아둔 컬렉션class= 분류의 라벨confidence= 모델이 해당 분류의 객체가 이미지에 포함되어 있다고 확신하는 정도
predicted_classes= 모델 예측에서 반환된 모든 분류(라벨/클래스)의 목록을 포함하는 배열image_path= 예측된 이미지의 경로prediction_type= 추론을 수행하는 데 사용된 모델 유형,ClassificationModel이 경우
// 예시 JSON 객체
{
"time": 0.19291414400004214,
"image": {
"width": 113,
"height": 210
},
"predictions": {
"dent": {
"confidence": 0.5253503322601318
},
"severe": {
"confidence": 0.5804202556610107
}
},
"predicted_classes": [
"dent",
"severe"
],
"image_path": "/car-model-343.jpg",
"prediction_type": "ClassificationModel"
}API 참조
Inference API 사용
POST https://classify.roboflow.com/:datasetSlug/:versionNumber
base64로 인코딩된 이미지를 모델 엔드포인트로 직접 POST할 수 있습니다. 또는 이미지가 이미 다른 곳에 호스팅되어 있다면 URL을 쿼리 문자열의 매개변수에 대해 입력 이미지를 선택하세요. 예측에는 모델 결과를 선택하세요. 선택적 구성 속성을 사용하여 경계 상자의 색상과 크기를 변경할 수 있습니다. 매개변수로 전달할 수 있습니다.
경로 매개변수
datasetSlug
string
데이터셋 이름의 URL-안전 버전입니다. 메인 프로젝트 보기의 URL을 확인하여 웹 UI에서 찾을 수 있습니다.
string
데이터셋 버전을 식별하는 버전 번호입니다.
쿼리 매개변수
api_key
string
워크스페이스 API 설정 페이지에서 얻은 API 키
{
"predictions":{
"bird":{
"confidence":0.5282308459281921
},
"cat":{
"confidence":0.5069406032562256
},
"dog":{
"confidence":0.49514248967170715
}
},
"predicted_classes":[
"bird",
"cat"
]
}{
"message":"Forbidden"
}jLast updated
Was this helpful?