[OpenR8 solution] HttpServer_DeepLearning (OpenR8 Caffe deep learning server)
  1. Chapter1: HttpServer_DeepLearning Intreoduction

 

The function of HttpServer_DeepLearning is to read the already trained caffemodel file, select the picture you want to test through a specific web page, and see the classification of the image.

 

At present, this solution can provide online testing classification of 20 categories (aircraft, bicycle, bird, boat, bottle, bus, car, cat, chair, cow, table, dog, horse, motorcycle, person, potted, sheep, sofa , train, TV monitor), if you want to add or change the classification type, please refer to other caffe for training.

 

The flow of HttpServer_DeepLearning is shown in Fig. 1, and each step is described in detail in the third chapter of this document.

 

Fig. 1. HttpServer_DeepLearning s process.png

Fig. 1. HttpServer_DeepLearning’s process.

 

 

  1. Chapter2: HttpServer_DeepLearning Folder Introduction

 

HttpServer_DeepLearning is located in the solution folder of OpenR8 and contains:

  1. Folder: data folder.
  2. flow files: HttpServer_DeepLearning.flow.
  3. Image: output.jpg (he webpage execution result graph will not be generated when no webpage execution results have been used).

 

Fig. 2. HttpServer_DeepLearning location.png

Fig. 2. HttpServer_DeepLearning location.

 

Fig. 3. HttpServer_DeepLearning folder.png

Fig. 3. HttpServer_DeepLearning folder.

 

There are three files in the “data folder”, and the “Caffe_ObjectDetect_ReadNet” function of [HttpServer_DeepLearning.flow] in the solution will be used.

  1. deploy.prototxt: The neural network structure model used by caffe.
  2. predefined_classes.txt: All category names at the time of training in caffemodel.
  3. VGG_VOC0712_SSD_300x300_iter_120000.caffemodel: The caffemodel file has been trained.

 

 

  1. Chpater3: Open and Run HttpServer_DeepLearning.flow

 

There is the “R8_Python3.6_CPU.bat or R8_Python3.6_GPU.bat” executable file under [OpenR8 folder]. See Fig. 4. Double-click to execute R8.exe.

 

Fig. 4. Run the R8_Python3.6_CPU.bat or R8_Python3.6_GPU.png

Fig. 4. Run the R8_Python3.6_CPU.bat or R8_Python3.6_GPU.bat.

 

Please click “File” => “Open” => “Enter the solution folder under OpenR8” => “Select HttpServer_DeepLearning folder” => “Select HttpServer_DeepLearning.flow”,as shown in Fig. 5, Fig. 6.

 

Fig. 5. Select HttpServer_DeepLearning.flow.png

Fig. 5. Select HttpServer_DeepLearning.flow.

 

Fig. 6. Open HttpServer_DeepLearning.flow.png

Fig. 6. Open HttpServer_DeepLearning.flow.

 

After loading, press the “Run” server.

 

Fig. 7. Run solution.png

Fig. 7. Run solution.

 

※ If No GPU appears, change the value of the GPU field GPU of [Caffe_ObjectDetect_ReadNet] to a null value.

 

  1. Chapter4: Open webpage detection image

 

Select the image to be tested through the web page, press Submit to send the result, and get the result of the image detection object. See Fig. 8, Fig. 9.

 

Fig. 8. Upload image by webpage.png

Fig. 8. Upload image by webpage.

 

Fig. 9. Detection results.png

Fig. 9. Detection results.

 

 

  1. Chapter5: HttpServer_DeepLearning.flow 

 

This chapter mainly introduces the function of the HttpServer_DeepLearning.flow process. Due to the large number of functions in the process, it may be difficult to find the parameters (variables) of the function you want to change at a time. The following table will provide the functions that may be changed. And content to help users quickly find the location of the parameter they want to change.

 

Features that may change by yourself

Located in the function

Changed parameter name

Remarks

Change to your own training caffemodel

Caffe_ObjectDetect_ReadNet

caffeModelPath: Press ... to choose your own training caffemodel

To confirm that the category of the analysis is also updated (next column).

Modify the txt of the category name (predefined_classes.txt)

Caffe_ObjectDetect_ReadNet

labelPath: The content of predefined_classes.txt is replaced with the category of training within caffemodel.

To confirm that the content of predefined_classes.txt is the same as the category of caffemodel training

Change the URL port of the test image

HttpServer_Set

Port: 8080 => Change to the port you want

The 8th point [Println] can be changed to the updated channel value by the way.

Set webpage connection time (timeout)

HttpServer_Set

TimeOut: 60 => Change to the connection time you want

 

Change test page content (display content of http://localhost:8080/)

String_Replace

inputString: pageContext’s value => Change to the content of the page you want to display

The webpage here is the way Html is written.

Change the content of the detection result page (the result display of http://localhost:8080/)

Point 29 String_Replace,

Point 30 String_Add

String6 and string7 combine to detect the content of the webpage.

The webpage here is the way Html is written.

Marker box color

Point 26 Image_DrawRectJson

Blue, green, red

 

 
 
  1. Caffe_Init:

Initialize Caffe.

 

  1. Caffe_ObjectDetect_ReadNet:

CaffeObject: The object from the previous “Caffe_Init”.

GPU: Choose whether to have GPU function, and default to CPU mode when not filling.

deployPath: Read [deploy.prototxt] in [data folder].

caffeModePath: Read [VGG_VOC0712_SSD_300x300_iter_120000.caffemodel] in the [data folder].

labelPath: Read [predefined_classes.txt] in the [data folder], which stores the names of all categories.

meanFilePath: Calculate the file path of the image mean, fill in null here.

 

Fig. 10. HttpServer_DeepLearning.flow - Caffe_ObjectDetect_ReadNet.png

Fig. 10. HttpServer_DeepLearning.flow - Caffe_ObjectDetect_ReadNet.

 

Fig. 11. You can use the method of selecting files to avoid mistakes..png

Fig. 11. You can use the method of selecting files to avoid mistakes.

 

  1. HttpServer_Init:

Initialize the web page for testing before making it.

 

  1. HttpServer_Set:

Set the port used by the test webpage, the number of executions, etc.

httpServer:

Select the object created by [HttpServer_Init].

result:

The success of the webpage setting.

port:

The port to which the webpage for testing is connected, fill in 8080 here.

documentRoot:

Set the starting position when reading or accessing, fill in “./”.

threadNum:

How many web pages can be executed at one time.

backlogNum:

A maximum of how many pages are allowed to respond.

timeout:

After the webpage has exceeded the number of seconds, it will not respond. Fill in 60 here.

 

 

Fig. 12. HttpServer_DeepLearning.flow - HttpServer_Set.png

Fig. 12. HttpServer_DeepLearning.flow - HttpServer_Set.

 

  1. String_Replace:

The usage here is to replace "/n" in the string with a blank string "". When editing the content of the webpage (the parameter filled in inputString), press ... next to the value, and a window will pop up to edit the content of the webpage. As shown in Fig. 13.

In order to be easy to read, beautiful, etc., the Enter key is used to wrap, but because the newline will use n to represent the newline in the string, the word n will appear in the string after the string is edited. As shown in Fig. 14, in order to restore the appearance of the string, as shown in Fig. 15, use [String_Replace] to replace n with a blank word.

 

※The word blank means nothing is filled in, not empty.

 

outputString: The output replaces "/n" with a string of "".

replaceFrom: Replace replaceFrom( /n ) of inputString (page content) with replaceTo().

replaceTo: Replace replaceFrom( /n ) of inputString (page content) with replaceTo().

inputString: Webpage content.

 

Fig. 13. HttpServer_DeepLearning.flow - String_Replace.png

Fig. 13. HttpServer_DeepLearning.flow - String_Replace.

 

Fig. 14. Webpage content of inputString.png

Fig. 14. Webpage content of inputString.

 

Fig. 15. The relationship between the Enter key and.png

Fig. 15. The relationship between the Enter key and /n.

 

Fig. 16. Normally no.png

Fig. 16. Normally no /n webpage source code.

 

  1. HttpServer_AddHtmlPage:

The content of the webpage output by [String_Replace] is output through this function to form a webpage pagination.

httpServer: Select the same object as “HttpServer_Set”.

pageName: The name you want to page.

pageContext: The content of the web page output by “String_Replace”.

 

Fig. 17. HttpServer_DeepLearning.flow - HttpServer_AddHtmlPage.png

Fig. 17. HttpServer_DeepLearning.flow - HttpServer_AddHtmlPage.

 

  1. Println:

The word "create a page in:" will be printed in the DOS window at runtime.

 

  1. Println:

At runtime, the words “http://localhost:8080/” will be printed in the DOS window. If your URL is changed, you can change the content yourself.

 

  1. HttpServer_Start:

Open the web server.

httpServer: Select the same object as [HttpServer_Set].

result: The result of the success of the return is opened.

 

  1. HttpServer_Accept:

Open the web server connection.

httpServer: Select the same object as [HttpServer_Set].

httpServerClient: The object of the client.

 

The following function needs to open the test web page to trigger and execute. For details on how to open the test web page, see Chapter 4.

 

  1. HttpServer_GetPostBinary:

Get the image content sent by the test webpage.

httpServerClient: Select the httpServerClient object that is output by [HttpServer_Accept].

result: If the webpage receives success or not, the value will be less than 0 when the reception fails.

binaryData: Received the image.

keyName: Name the received image.

 

Fig. 18. HttpServer_DeepLearning.flow.png

Fig. 18. HttpServer_DeepLearning.flow-HttpServer_GetPostBinary.

 

  1. Int_Compare:

Check if the reception of [HttpServer_GetPostBinary] has failed, so compare it with 0.

intA: The result of [HttpServer_GetPostBinary] output.

intB: Fill in the number 0.

mode: Enter the number 1 (for <).

bool: Output "Integer A" is less than "Integer B", "Integer A" is less than "Integer B" is True (1), "Integer A" is greater than or equal to "Integer B" is False (0).

 

Fig. 19. HttpServer_DeepLearning.flow - Int_Compare.png

Fig. 19. HttpServer_DeepLearning.flow - Int_Compare.

 

  1. If:

If the result of [Int_Compare] is False, the next 14. to 17. will not be executed.

This conditional expression means that if the reception of [HttpServer_GetPostBinary] fails, the word "!!!!!!! File result: " is printed in the DOS window.

IfObj: Create a conditional object.

bool: Whether to start the conditional expression, fill in the result of [Int_compare].

 

  1. Println:

The "!!!!!!! File result:+[HttpServer_GetPostBinary] output result will be printed in the DOS window during runtime.

 

  1. HttpServer_Write:

“No Image File” is displayed on the web page.

HttpServerClient: Select the httpServerClient object that is output by [HttpServer_Accept].

String: Output the displayed string (No Image File).

 

Fig. 20. HttpServer_DeepLearning.flow - HttpServer_Write.png

Fig. 20. HttpServer_DeepLearning.flow - HttpServer_Write.

 

  1. HttpServer_Loop:

Go back to [HttpServer_Accept] and wait to accept other clients (clients).

httpServer: Select the same object as [HttpServer_Accept]

 

  1. If_End:

In the conditional expression (point 13) to [HttpServer_Loop] (point 16), the function that will be performed when the conditional expression (point 13) is satisfied needs to be pulled [conditional end] for [conditional] This is the end of the matter.

Conditional object: Select the same item as [Conditional].

 

  1. Image_OpenBinary:

Convert the binary data received by [HttpServer_GetPostBinary] into a image file.

result: The success or failure of the conversion will be less than 0.

image: Output the converted image file.

BinaryData: Enter the binary data received by [HttpServer_GetPostBinary].

 

Fig. 21. HttpServer_DeepLearning.flow - Image_OpenBinary.png

Fig. 21. HttpServer_DeepLearning.flow - Image_OpenBinary.

 

  1. Int_Compare:

Confirm whether the image converted by [Image_OpenBinary] has failed, so it is compared with 0.

IntA: The result of [HttpServer_GetPostBinary] output.

IntB: Enter the number 0.

mode: Enter the number 1 (for <).

bool: Output "Integer A" is less than "Integer B", "Integer A" is less than "Integer B" is True (1), "Integer A" is greater than or equal to "Integer B" is False (0).

 

  1. If:

If the result of [Int_Compare] (point. 19) is False, the next 21. to 24. will not be executed.

This conditional expression means that if [Image_OpenBinary] is converted to a image file (such as no image, or not a image file...), the word "conversion failed" is printed in the DOS window.

ifObj: Create a conditional object.

bool: Whether to start the conditional expression, fill in the result of [Int_Compare].

 

Fig. 22. HttpServer_DeepLearning.flow -Int_Compare.png

Fig. 22. HttpServer_DeepLearning.flow -Int_Compare.

 

  1. Println:

When executed, "!!!!!!! Image_Open result: + [Image_OpenBinary] output result" will be printed in the DOS window.

 

  1. HttpServer_Write:

"Image decode fail!" is displayed on the webpage.

HttpServerClient: Select the httpServerClient object output by [HttpServer_Accept].

String: Output the displayed string (Image decode fail!).

 

Fig. 23. HttpServer_DeepLearning.flow - HttpServer_Write.png

Fig. 23. HttpServer_DeepLearning.flow - HttpServer_Write.

 

  1. HttpServer_Loop:

Go back to [HttpServer_Accept] and wait for other client.

httpServer: Select the same object as [HttpServer_Accept].

 

  1. If_End:

In [If] (20th point) to [HttpServer_Loop] (point 23) The function that will be done when the [If] (20th point) is satisfied, it is necessary to pull [If_End] to represent what [If] has done so far.

ifObj: Select the same item as [If] (20th point).

 

  1. Caffe_ObjectDetect_InferenceImage:

Feed the image converted by [Image_OpenBinary] to Caffe to detect if it has a category.

caffeObject: The caffeObject object selected by [Caffe_ObjectDetect_ReadNet] (point 2).

outputResult: Output the result of the detection.

GPU: Whether it has GPU acceleration or not, it is preset to CPU mode when not filling.

image: The converted image by “Image_OpenBinary”.

confidenceThreshold: Detection threshold.

 

Fig. 24. HttpServer_DeepLearning.flow - Caffe_ObjectDetect_InferenceImage.png

Fig. 24. HttpServer_DeepLearning.flow - Caffe_ObjectDetect_InferenceImage.

 

  1. Image_DrawRectJson:

If the previous point [Caffe_ObjectDetect_InferenceImage] has judged the category, the position will be output in the form of Json, where Json is read in and drawn in the image output by [Image_OpenBinary].

image

Select the image output by [Image_OpenBinary].

json:

Select the outputResult output by [Caffe_Object Detect_Inference Image].

imageDrawRectJson:

Outputs an image of the rectangle.

thickness:

Set the thickness of the rectangle (the bigger the thicker).

blue:

Since you want to use a green box here, set 0.

green:

Since you want to use a green box here, set 255.

red:

Since you want to use a green box here, set 0.

padding:

Whether to fill the rectangle, is 1 or not 0, fill in 0 here.

isShowType:

Whether to display the category name, is 1 or not 0, here is 1.

stringSize:

If you want to display the font size setting when it is displayed, fill in (1.0) here.

 

Fig. 25. HttpServer_DeepLearning.flow - Image_DrawRectJson.png

Fig. 25. HttpServer_DeepLearning.flow - Image_DrawRectJson.

 

  1. Image_Save:

The image result drawn by [Image_DrawRectJson] is output as image.

image: Select the image json square image output by [Image_DrawRectJson]. ImageFileName: stored file name.

 

Fig. 26. HttpServer_DeepLearning.flow - Image_Save.png

Fig. 26. HttpServer_DeepLearning.flow - Image_Save.

 

  1. Json_ToString:

The outputResult detection result output by [Caffe_object detection_image inference] is converted from json format to string format.

 

  1. String_Replace:

Use line string substitution to join a web page with a newline ( <br> ).

outputString: The output replaces "} ̧" with the string "} ̧<br>".

replaceFrom: Replace replaceFrom(},) of inputString (the content of the page) with replaceTo(} ̧<br>).

replaceTo: Replace replaceFrom(},) of inputString (page content) with replaceTo(},<br>).

inputString: Detect the content of the result.

 

Fig. 27. HttpServer_DeepLearning.flow - String_Replace.png

Fig. 27. HttpServer_DeepLearning.flow - String_Replace.

 

  1. String_Add:

In the content of the detection result to be output to the web page, the output result image (html writing method) is added.

output: StringA + StringB.

StringA: The string of “String_Replace” output.

StringB: Output the resulting image (html).

 

Fig. 28. Output result image html .png

Fig. 28. Output result image (html).

 

  1. Int_Add:

The image category analysis performed several times was calculated.

intA: The parameter to be calculated.

intB: Add 1 for each execution, so fill in 1.

intC: Calculates the parameter of + 1 (fill in the same parameter as the intA).

 

Fig. 29. HttpServer_DeepLearning.flow - Int_Add.png

Fig. 29. HttpServer_DeepLearning.flow - Int_Add.

 

  1. (Gray) Int_Compare:

As noted in the note, if enabled, turn off the server after performing three image category analyses.

intA: The number of calculations output by “Int_Add”.

intB: Fill in the number 3.

mode: Fill in the number 2 (represents = equal to).

bool: Output "IntA" is equal to "IntB", equal to True (1), not equal to False (0).

 

Fig. 30. HttpServer_DeepLearning.flow -Int_Compare.png

Fig. 30. HttpServer_DeepLearning.flow -Int_Compare.

 

  1. If:

If [Int_Compare] (point 32) is not turned on or the output is False, the next 33. to 36. will not be executed.

This conditional expression is intended to turn off the server after performing three times image category analysis.

ifObj: Create a conditional object.

bool: Whether to start the conditional expression, fill in the result of [Int_Compare] (point 32).

 

Fig. 31. HttpServer_DeepLearning.flow - If.png

Fig. 31. HttpServer_DeepLearning.flow - If.

 

  1. HttpServer_Write:

"Server is close." is displayed on the webpage.

HttpServerClient: Select the httpServerClient object output by [HttpServer_Accept].

String: Output the displayed string (Server is close.).

 

Fig. 32. HttpServer_DeepLearning.flow - HttpServer_Write.png

Fig. 32. HttpServer_DeepLearning.flow - HttpServer_Write.

 

  1. Println:

Print "HttpServer Stop" in the DOS window.

 

  1. If_Else:

If [Int_Compare] (point 32) is not turned on or the output is Fasle, the content to be displayed on the webpage is [String_Add].

ifObj: Select the same object as [If] (point 33).

※[If_Else] cannot exist alone. It must have [If] in front of it. In other words, there is no [If_Else] without [If], but [If] does not necessarily have [If_Else] .

※ In terms of program syntax, [If] = if, and [If_Else] = else.

 

  1. ​​HttpServer_Write:

The content of [String_Add] is displayed on the webpage.

HttpServerClient: Select the httpServerClient object that is output by [HttpServer_Accept].

String: Output the displayed string (Server is close.).

 

  1. If_End:

In [If] (point 33) to [HttpServer_Write] (point 38) To satisfy the [If] (point 33) and [If_Else] functions, you need to pull [If_End] to represent [If] and [If_Else] have done so far.

ifObj: Select the same object as [If].

 

  1. HttpServer_Loop:

Go back to [HttpServer_Accept] and wait for other clients.

httpServer: Select the same object as [HttpServer_Accept].

 

  1. HttpServer_Close:

Turn off the server.

httpServer: Select the httpServerClient object that is output by [HttpServer_Accept].

 

  1. Println:

Print "HttpServer_Close" in the DOS window.


Recommended Article

1.
OpenR8 - AI Software for Everyone (Download)