heojae / FoodImageRotationAdmin

Food Image Rotation (음식이미지 회전) 이라는 주제에 대해서. 실제로 딥러닝(deeplearning)을 어떻게 도입하고, 이를 API(backend)로서 서버에 올리며, 웹(frontend) 를 통해서 올리는 과정을 구현하기 위해서 만든 프로젝트입니다.
0 stars 0 forks source link

[Protobuf] 필요한 API 대한 정리와 통신 정리 #13

Open heojae opened 3 years ago

heojae commented 3 years ago

대주제 : Proto Buf 를 통해, 필요한 API 를 정리하고 싶다.

소주제 : 프론트와 서버간의 통신 뿐만 아니라, 서버와 서버간의 모든 필요한 통신에 대해서, 정리하고 싶다.

service User {
  // email 과 password 를 받아, 인물의 정보를 돌려준다.  
  rpc Login(LoginInfo) returns (UserInfo) {}; 

  // access_token 을 header 에 담아, 올바른 access_token 인지 판단한다. (서버 <-> 서버, 유저 인증용으로 사용될 예정)
  rpc Authenticate(Empty) returns (Empty) {};

  // access_token 을 통해, 유저의 정보를 돌려준다. (서버 <-> 프론트, 브라우저 Cookie 를 통해 유저 인증용으로 사용될 예정)
  rpc AuthenticateGetUserInfo(Empty) returns (UserInfo) {}; 
}

user server 를 제외하고, 다른 서버들의 API 들은 프론트에서, request를 받을 때,

rpc Authenticate(Empty) returns (Empty) {} 을 통해, requestuser 인증을 한다.


service InferenceFoodImage {
  // image(binary) -> base64 encode -> ascii string 을 통해서, 이미지를 string 으로 받고, 
  // 결과를 돌려보내준다. 
  rpc Inference(FoodB64Image) returns (InferenceResult) {};

  // model 의 path 를 보내줌으로서, dl_server 에서, DB가 없더라도, 단순히 모델의 경로값만 받아서, 새로운 모델을 로드한다. 
  rpc LoadModel(ModelPath) returns (Empty){};
}

service ModelVersion {
  // 현재 사용중인 모델의 버젼에 대한 정보를 보내준다. 
  rpc GetUsingModelVersion(Empty) returns (ModelVersionInfo) {};

  // 모든 모델의 버젼에 대한 정보들을 들고온다. 
  rpc GetAllModelVersion(Empty) returns (stream ModelVersionInfo) {};

  // 선택한 모델의 pk 를 바탕으로, 사용중인 모델의 버젼을 바꾼다. 
  rpc Change(SelectedModelVersion) returns (Empty) {};
}

service Dataset {
  // 모든 데이터 셋의 정보를 들고온다. 
  rpc GetDatasetInfoList(Empty) returns (stream DatasetInfo) {};

  // 모든 이미지 정보를 들고온다. 
  rpc GetImageInfoList(Empty) returns (stream ImageInfo) {};

  // 선택된 데이터 셋에 포함된 이미지 정보를 들고온다. 
  rpc GetChooseImageInfoList(SelectedDatasetInfo) returns (stream ImageInfo) {};

  // 선택된 이미지의 정보를 제거한다. 
  rpc RemoveImage(SelectedImageInfo) returns (Empty){};

  // 기존의, no_named_dataset 에 새로운 이름을 부여해주고, 새로운 no_named_dataset 을 생성한다. 
  rpc CreateDatasetInfo(NewDatasetInfo) returns (Empty){};
}
service UserFixImage {
  // 사용자가 수정한 정보를 바탕으로, no_named_dataset 에 새로운 이미지를 추가한다. 
  rpc SaveUserFixImage(UserFixedB64ImageInfo) returns (Empty) {};
}
heojae commented 3 years ago

https://github.com/heojae/FoodImageRotationAdmin/pull/22#issue-572278403 에서 변경된것 과 같이,

inference.protouser_fix_image.proto 가 변경되었습니다.

기존의 경우, string 을 통해 받았던, 이미지 값들을 bytes 형태로 수정하였습니다.

inference.proto

syntax = "proto3";
import "empty.proto";

message BytesImage {
  bytes image_content = 1;
}

message InferenceResult {
  int32 model_degree = 1;
  int32 exif_degree = 2;
  float confidence = 3;
  bool success = 4;
}

message ModelPath{
  string path = 1;
}

service InferenceImage {
  rpc Inference(BytesImage) returns (InferenceResult) {};
  rpc LoadModel(ModelPath) returns (Empty){};
}

user_fix_image.proto

syntax = "proto3";
import "empty.proto";

message UserFixedImageInfo {
  bytes image_content = 1;
  string file_name = 2;
  int32 exif_degree = 3;
  int32 model_degree = 4;
  float confidence = 5;
  int32 user_fix_degree = 6;
}

service UserFixImage {
  rpc SaveUserFixImage(UserFixedImageInfo) returns (Empty) {};
}