|
|
@@ -661,6 +661,8 @@ paddlex --pipeline seal_recognition \
|
|
|
--save_path ./output
|
|
|
```
|
|
|
|
|
|
+<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"` to change the model source to BOS. In the future, more model sources will be supported.
|
|
|
+
|
|
|
The relevant parameter descriptions can be referred to in the parameter explanations of [2.1.2 Integration via Python Script](#212-integration-via-python-script). Supports specifying multiple devices simultaneously for parallel inference. For details, please refer to the documentation on pipeline parallel inference.
|
|
|
|
|
|
After running, the results will be printed to the terminal, as follows:
|
|
|
@@ -1505,98 +1507,98 @@ public class Main {
|
|
|
<pre><code class="language-go">package main
|
|
|
|
|
|
import (
|
|
|
- "bytes"
|
|
|
- "encoding/base64"
|
|
|
- "encoding/json"
|
|
|
- "fmt"
|
|
|
- "io/ioutil"
|
|
|
- "net/http"
|
|
|
+ "bytes"
|
|
|
+ "encoding/base64"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "io/ioutil"
|
|
|
+ "net/http"
|
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
- API_URL := "http://localhost:8080/seal-recognition"
|
|
|
- filePath := "./demo.jpg"
|
|
|
-
|
|
|
- fileBytes, err := ioutil.ReadFile(filePath)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Error reading file: %v\n", err)
|
|
|
- return
|
|
|
- }
|
|
|
- fileData := base64.StdEncoding.EncodeToString(fileBytes)
|
|
|
-
|
|
|
- payload := map[string]interface{}{
|
|
|
- "file": fileData,
|
|
|
- "fileType": 1,
|
|
|
- }
|
|
|
- payloadBytes, err := json.Marshal(payload)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Error marshaling payload: %v\n", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- client := &http.Client{}
|
|
|
- req, err := http.NewRequest("POST", API_URL, bytes.NewBuffer(payloadBytes))
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Error creating request: %v\n", err)
|
|
|
- return
|
|
|
- }
|
|
|
- req.Header.Set("Content-Type", "application/json")
|
|
|
-
|
|
|
- resp, err := client.Do(req)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Error sending request: %v\n", err)
|
|
|
- return
|
|
|
- }
|
|
|
- defer resp.Body.Close()
|
|
|
-
|
|
|
- if resp.StatusCode != http.StatusOK {
|
|
|
- fmt.Printf("Unexpected status code: %d\n", resp.StatusCode)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- body, err := ioutil.ReadAll(resp.Body)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Error reading response body: %v\n", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- type SealResult struct {
|
|
|
- PrunedResult map[string]interface{} `json:"prunedResult"`
|
|
|
- OutputImages map[string]string `json:"outputImages"`
|
|
|
- InputImage *string `json:"inputImage"`
|
|
|
- }
|
|
|
-
|
|
|
- type Response struct {
|
|
|
- Result struct {
|
|
|
- SealRecResults []SealResult `json:"sealRecResults"`
|
|
|
- DataInfo interface{} `json:"dataInfo"`
|
|
|
- } `json:"result"`
|
|
|
- }
|
|
|
-
|
|
|
- var respData Response
|
|
|
- if err := json.Unmarshal(body, &respData); err != nil {
|
|
|
- fmt.Printf("Error unmarshaling response: %v\n", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- for i, res := range respData.Result.SealRecResults {
|
|
|
- fmt.Printf("Pruned Result %d: %+v\n", i, res.PrunedResult)
|
|
|
-
|
|
|
- for name, imgBase64 := range res.OutputImages {
|
|
|
- imgBytes, err := base64.StdEncoding.DecodeString(imgBase64)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Error decoding image %s: %v\n", name, err)
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- filename := fmt.Sprintf("%s_%d.jpg", name, i)
|
|
|
- if err := ioutil.WriteFile(filename, imgBytes, 0644); err != nil {
|
|
|
- fmt.Printf("Error saving image %s: %v\n", filename, err)
|
|
|
- continue
|
|
|
- }
|
|
|
- fmt.Printf("Output image saved at %s\n", filename)
|
|
|
- }
|
|
|
- }
|
|
|
+ API_URL := "http://localhost:8080/seal-recognition"
|
|
|
+ filePath := "./demo.jpg"
|
|
|
+
|
|
|
+ fileBytes, err := ioutil.ReadFile(filePath)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("Error reading file: %v\n", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fileData := base64.StdEncoding.EncodeToString(fileBytes)
|
|
|
+
|
|
|
+ payload := map[string]interface{}{
|
|
|
+ "file": fileData,
|
|
|
+ "fileType": 1,
|
|
|
+ }
|
|
|
+ payloadBytes, err := json.Marshal(payload)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("Error marshaling payload: %v\n", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ client := &http.Client{}
|
|
|
+ req, err := http.NewRequest("POST", API_URL, bytes.NewBuffer(payloadBytes))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("Error creating request: %v\n", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ req.Header.Set("Content-Type", "application/json")
|
|
|
+
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("Error sending request: %v\n", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ if resp.StatusCode != http.StatusOK {
|
|
|
+ fmt.Printf("Unexpected status code: %d\n", resp.StatusCode)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ body, err := ioutil.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("Error reading response body: %v\n", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ type SealResult struct {
|
|
|
+ PrunedResult map[string]interface{} `json:"prunedResult"`
|
|
|
+ OutputImages map[string]string `json:"outputImages"`
|
|
|
+ InputImage *string `json:"inputImage"`
|
|
|
+ }
|
|
|
+
|
|
|
+ type Response struct {
|
|
|
+ Result struct {
|
|
|
+ SealRecResults []SealResult `json:"sealRecResults"`
|
|
|
+ DataInfo interface{} `json:"dataInfo"`
|
|
|
+ } `json:"result"`
|
|
|
+ }
|
|
|
+
|
|
|
+ var respData Response
|
|
|
+ if err := json.Unmarshal(body, &respData); err != nil {
|
|
|
+ fmt.Printf("Error unmarshaling response: %v\n", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for i, res := range respData.Result.SealRecResults {
|
|
|
+ fmt.Printf("Pruned Result %d: %+v\n", i, res.PrunedResult)
|
|
|
+
|
|
|
+ for name, imgBase64 := range res.OutputImages {
|
|
|
+ imgBytes, err := base64.StdEncoding.DecodeString(imgBase64)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("Error decoding image %s: %v\n", name, err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ filename := fmt.Sprintf("%s_%d.jpg", name, i)
|
|
|
+ if err := ioutil.WriteFile(filename, imgBytes, 0644); err != nil {
|
|
|
+ fmt.Printf("Error saving image %s: %v\n", filename, err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ fmt.Printf("Output image saved at %s\n", filename)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
</code></pre></details>
|
|
|
|