Skip to content

Commit 0de01eb

Browse files
EFRS-1333: Changed REST API docs due to change requests
1 parent 7dd0de0 commit 0de01eb

File tree

5 files changed

+56
-53
lines changed

5 files changed

+56
-53
lines changed

docs/Rest-API-description.md

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
+ [Face Detection Service](#face-detection-service)
2424
+ [Face Verification Service](#face-verification-service)
2525
+ [Base64 Support](#base64-support)
26+
+ [Recognition and verification using embedding](#recognition-and-verification-using-embedding)
2627

2728
To know more about face services and face plugins visit [this page](Face-services-and-plugins.md).
2829

@@ -833,33 +834,35 @@ curl -X POST "http://localhost:8000/api/v1/verification/verify?limit=<limit>&pre
833834

834835

835836

836-
## Embedding Support
837+
## Recognition and verification using embedding
837838
`since 1.2.0 version`
838839

839-
If you already have a computed embedding, you can use it to perform recognition and verification.
840+
You can use computed embedding to perform recognition and verification. To obtain embedding, you can
841+
use [calculator plugin](https://github.com/exadel-inc/CompreFace/blob/EFRS-1333_ability_to_send_embeddings_instead_of_the_image_for_recognition/docs/Face-services-and-plugins.md#face-plugins)
842+
in each Face service.
840843
The base rule is to use `Content-Type: application/json` header and send JSON in the body.
841844

842-
### Embedding Recognition Service
843-
The service is used to determine similarities between input embeddings and embeddings within the database. An example:
845+
### Recognize Faces from a Given Image, Embedding
846+
The service is used to determine similarities between input embeddings and embeddings within the Face Collection. An example:
844847

845848
```shell
846849
curl -X POST "http://localhost:8000/api/v1/recognition/embeddings/recognize?prediction_count=<prediction_count>" \
847850
-H "Content-Type: application/json" \
848851
-H "x-api-key: <service_api_key>" \
849-
-d {"embeddings": "<array_of_embeddings>"}
852+
-d {"embeddings": [[<array_of_embedding>], ...]}
850853
```
851854

852855
| Element | Description | Type | Required | Notes |
853856
|------------------|-------------|---------|----------|-----------------------------------------------------------------------------------------------------------------|
854857
| Content-Type | header | string | required | application/json |
855-
| x-api-key | header | string | required | an api key of the Embedding recognition service, created by the user |
856-
| embeddings | body | array | required | an input embeddings. The length must be 512 for each of them |
858+
| x-api-key | header | string | required | an api key of the Face recognition service, created by the user |
859+
| embeddings | body | array | required | an input embeddings. The length depends on the model (e.g. 512 or 128) |
857860
| prediction_count | param | integer | optional | the maximum number of subject predictions per embedding. It returns the most similar subjects. Default value: 1 |
858861

859862
Response body on success:
860863
```json
861864
{
862-
"results": [
865+
"result": [
863866
{
864867
"embedding": [0.0627421774604647, "...", -0.0236684433507126],
865868
"similarities": [
@@ -877,33 +880,33 @@ Response body on success:
877880

878881
| Element | Type | Description |
879882
|--------------|--------|--------------------------------------------------------------------------------------------|
880-
| results | array | an array that contains all the results |
881-
| embedding | array | an embedding that is similar to the input embedding |
883+
| result | array | an array that contains all the results |
884+
| embedding | array | an input embedding |
882885
| similarities | array | an array that contains results of similarity between the embedding and the input embedding |
883886
| subject | string | a subject in which the similar embedding was found |
884887
| similarity | float | a similarity between the embedding and the input embedding |
885888

886-
### Embedding Verification Service
889+
### Face Verification Service, Embedding
887890
The service is used to determine similarities between an input source embedding and input target embeddings. An example:
888891

889892
```shell
890893
curl -X POST "http://localhost:8000/api/v1/verification/embeddings/verify" \
891894
-H "Content-Type: application/json" \
892895
-H "x-api-key: <service_api_key>" \
893-
-d {"source": "<source_embedding>"; "targets": "array_of_target_embeddings"}
896+
-d {"source": [<source_embedding>], "targets": [["target_embedding"], ...]}
894897
```
895898

896-
| Element | Description | Type | Required | Notes |
897-
|------------------|-------------|---------|----------|--------------------------------------------------------------------|
898-
| Content-Type | header | string | required | application/json |
899-
| x-api-key | header | string | required | api key of the Embedding verification service, created by the user |
900-
| source | body | array | required | the source embedding. The length must be 512 |
901-
| targets | body | array | required | the target embeddings. The length must be 512 for each of them |
899+
| Element | Description | Type | Required | Notes |
900+
|------------------|-------------|---------|----------|--------------------------------------------------------------------------------------|
901+
| Content-Type | header | string | required | application/json |
902+
| x-api-key | header | string | required | api key of the Face verification service, created by the user |
903+
| source | body | array | required | an input embeddings. The length depends on the model (e.g. 512 or 128) |
904+
| targets | body | array | required | an array of the target embeddings. The length depends on the model (e.g. 512 or 128) |
902905

903906
Response body on success:
904907
```json
905908
{
906-
"results": [
909+
"result": [
907910
{
908911
"embedding": [0.0627421774604647, "...", -0.0236684433507126],
909912
"similarity": 0.55988
@@ -913,33 +916,33 @@ Response body on success:
913916
}
914917
```
915918

916-
| Element | Type | Description |
917-
|--------------|--------|--------------------------------------------------------------------|
918-
| results | array | an array that contains all the results |
919-
| embedding | array | a target embedding that is similar to the source embedding |
920-
| similarity | float | a similarity between the source embedding and the target embedding |
919+
| Element | Type | Description |
920+
|-------------|--------|--------------------------------------------------------------------|
921+
| result | array | an array that contains all the results |
922+
| embedding | array | a target embedding which we are comparing to source embedding |
923+
| similarity | float | a similarity between the source embedding and the target embedding |
921924

922-
### Verify Embeddings using Given Embedding
923-
The endpoint is used to compare input embeddings to the embedding by its id. An example:
925+
### Verify Faces from a Given Image, Embedding
926+
The endpoint is used to compare input embeddings to the embedding stored in Face Collection. An example:
924927

925928
```shell
926-
curl -X POST "http://localhost:8000/api/v1/recognition/embeddings/faces/{embeddingId}/verify" \
929+
curl -X POST "http://localhost:8000/api/v1/recognition/embeddings/faces/{image_id}/verify" \
927930
-H "Content-Type: application/json" \
928931
-H "x-api-key: <service_api_key>" \
929-
-d {"embeddings": "<array_of_embeddings>"}
932+
-d {"embeddings": [[<array_of_embeddings>], ...]}
930933
```
931934

932-
| Element | Description | Type | Required | Notes |
933-
|--------------|-------------|--------|----------|-------------------------------------------------------------------|
934-
| Content-Type | header | string | required | application/json |
935-
| x-api-key | header | string | required | api key of the Embedding recognition service, created by the user |
936-
| embeddings | body | array | required | input target embeddings. The length must be 512 for each of them |
937-
| embedding_id | variable | UUID | required | an id of the source embedding within the database |
935+
| Element | Description | Type | Required | Notes |
936+
|--------------|-------------|--------|----------|------------------------------------------------------------------------|
937+
| Content-Type | header | string | required | application/json |
938+
| x-api-key | header | string | required | api key of the Face recognition service, created by the user |
939+
| embeddings | body | array | required | an input embeddings. The length depends on the model (e.g. 512 or 128) |
940+
| image_id | variable | UUID | required | an id of the source embedding within the Face Collection |
938941

939942
Response body on success:
940943
```json
941944
{
942-
"results": [
945+
"result": [
943946
{
944947
"embedding": [0.0627421774604647, "...", -0.0236684433507126],
945948
"similarity": 0.55988
@@ -949,8 +952,8 @@ Response body on success:
949952
}
950953
```
951954

952-
| Element | Type | Description |
953-
|--------------|--------|--------------------------------------------------------------------|
954-
| results | array | an array that contains all the results |
955-
| embedding | array | a target embedding that is similar to the source embedding |
956-
| similarity | float | a similarity between the source embedding and the target embedding |
955+
| Element | Type | Description |
956+
|-------------|--------|------------------------------------------------------------------------------|
957+
| result | array | an array that contains all the results |
958+
| embedding | array | a source embedding which we are comparing to embedding from Face Collection |
959+
| similarity | float | a similarity between the source embedding and embedding from Face Collection |

java/api/src/main/java/com/exadel/frs/core/trainservice/controller/EmbeddingController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,14 @@ public VerificationResult recognizeBase64(
310310
);
311311
}
312312

313-
@PostMapping(value = "/embeddings/faces/{embeddingId}/verify", consumes = MediaType.APPLICATION_JSON_VALUE)
313+
@PostMapping(value = "/embeddings/faces/{imageId}/verify", consumes = MediaType.APPLICATION_JSON_VALUE)
314314
public EmbeddingsVerificationProcessResponse recognizeEmbeddings(
315315
@ApiParam(value = API_KEY_DESC, required = true)
316316
@RequestHeader(X_FRS_API_KEY_HEADER)
317317
final String apiKey,
318318
@ApiParam(value = IMAGE_ID_DESC, required = true)
319319
@PathVariable
320-
final UUID embeddingId,
320+
final UUID imageId,
321321
@RequestBody
322322
@Valid
323323
final EmbeddingsRecognitionRequest recognitionRequest
@@ -326,7 +326,7 @@ public EmbeddingsVerificationProcessResponse recognizeEmbeddings(
326326
ProcessEmbeddingsParams.builder()
327327
.apiKey(apiKey)
328328
.embeddings(recognitionRequest.getEmbeddings())
329-
.additionalParams(Map.of(IMAGE_ID, embeddingId))
329+
.additionalParams(Map.of(IMAGE_ID, imageId))
330330
.build();
331331

332332
return subjectService.verifyEmbedding(processParams);

java/api/src/main/java/com/exadel/frs/core/trainservice/dto/EmbeddingsRecognitionProcessResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
@AllArgsConstructor
1313
public class EmbeddingsRecognitionProcessResponse implements EmbeddingsProcessResponse {
1414

15-
private List<EmbeddingRecognitionProcessResult> results;
15+
private List<EmbeddingRecognitionProcessResult> result;
1616
}

java/api/src/main/java/com/exadel/frs/core/trainservice/dto/EmbeddingsVerificationProcessResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
@AllArgsConstructor
1313
public class EmbeddingsVerificationProcessResponse implements EmbeddingsProcessResponse {
1414

15-
private List<EmbeddingVerificationProcessResult> results;
15+
private List<EmbeddingVerificationProcessResult> result;
1616
}

java/api/src/test/java/com/exadel/frs/core/trainservice/service/EmbeddingsRecognizeProcessServiceImplTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ void processEmbeddings_TheInputEmbeddingExistsInTheDatabase_ShouldReturnComplete
7575
when(predictor.predict(any(), any(), anyInt())).thenReturn(List.of(Pair.of(1.0, "subject")));
7676
assertThat(embeddingRepository.findAll()).containsOnly(embedding);
7777

78-
var results = recognizeProcessService.processEmbeddings(params).getResults();
78+
var results = recognizeProcessService.processEmbeddings(params).getResult();
7979

8080
assertThat(embeddingRepository.findAll()).containsOnly(embedding);
8181
assertThat(results).isNotEmpty().hasSize(1);
8282

8383
var result = results.get(0);
8484

8585
assertThat(result.getEmbedding()).isEqualTo(embedding.getEmbedding());
86-
assertThat(result.getResults()).isNotEmpty().hasSize(1);
87-
assertThat(result.getResults().get(0).getSimilarity()).isEqualTo(1.0F);
88-
assertThat(result.getResults().get(0).getSubject()).isEqualTo("subject");
86+
assertThat(result.getSimilarities()).isNotEmpty().hasSize(1);
87+
assertThat(result.getSimilarities().get(0).getSimilarity()).isEqualTo(1.0F);
88+
assertThat(result.getSimilarities().get(0).getSubject()).isEqualTo("subject");
8989
}
9090

9191
@Test
@@ -103,17 +103,17 @@ void processEmbeddings_TheInputEmbeddingDoesNotExistInTheDatabase_ShouldNotRetur
103103
when(predictor.predict(any(), any(), anyInt())).thenReturn(List.of(Pair.of(0.0, "subject")));
104104
assertThat(embeddingRepository.findAll()).containsOnly(embedding);
105105

106-
var results = recognizeProcessService.processEmbeddings(params).getResults();
106+
var results = recognizeProcessService.processEmbeddings(params).getResult();
107107

108108
assertThat(embeddingRepository.findAll()).containsOnly(embedding);
109109
assertThat(results).isNotEmpty().hasSize(1);
110110

111111
var result = results.get(0);
112112

113113
assertThat(result.getEmbedding()).isNotEqualTo(embedding.getEmbedding());
114-
assertThat(result.getResults()).isNotEmpty().hasSize(1);
115-
assertThat(result.getResults().get(0).getSimilarity()).isEqualTo(0.0F);
116-
assertThat(result.getResults().get(0).getSubject()).isEqualTo("subject");
114+
assertThat(result.getSimilarities()).isNotEmpty().hasSize(1);
115+
assertThat(result.getSimilarities().get(0).getSimilarity()).isEqualTo(0.0F);
116+
assertThat(result.getSimilarities().get(0).getSubject()).isEqualTo("subject");
117117
}
118118

119119
@ParameterizedTest

0 commit comments

Comments
 (0)