Local Pycharm connects to remote server training model tutorial - yolov5 as an example

Issues addressed in this article:

The local pycharm and the cloud server/lab server are remotely connected to run experimental training, and all or part of the files between the local and cloud servers are synchronized.

The work that needs to be done before this:
1. The virtual environment has been created on the server (you can read the next article if you don’t know it): use cloud GPU for yolov5 training_gpu training cloud server_Geng Gui drinking coconut milk blog- CSDN blog
2. You have installed pycharm locally (remote connection is only supported by the professional version of Pycharm)

Table of contents

1. Establish a remote server connection

1. Check whether Pycharm is a professional version

2. The virtual environment has been created on the server

 3. Start creating a remote connection

(1) Configure the remote environment

(2) Establish ssh connection

( 3 ) Configure SSH connection 

4. Perform folder path mapping between local projects and remote projects

 5. Set automatic upload project

6. Verify that the connection is successful

2. Configure the Python interpreter locally

3. Start the server terminal locally

Four, pay attention


1. Establish a remote server connection

1. Check whether Pycharm is a professional version

      Pycharm is divided into professional version and community version. Only the professional version supports remote services, so you can confirm your own version of Pycharm first, and you can check your version through the operation shown in the figure below (toolbar help (help) -> about ( about ) ):

2. The virtual environment has been created on the server

See the following articles for details:

(2 messages) Use cloud GPU for yolov5 training_gpu training cloud server_Geng Gui drinking coconut milk blog-CSDN blogUsing cloud GPU for yolov5 training_gpu training cloud server_Geng Gui drinking coconut milk blog-CSDN Blog (2 messages) Use cloud GPU for yolov5 training_gpu training cloud server_Geng Gui drinking coconut milk blog-CSDN blog

 After checking that the version is correct and the virtual environment is created, start configuring the connection between the local and remote servers:

 3. Start creating a remote connection

      The first step is to establish an SSH connection between the local and the remote server. We know that the instance created on the remote server has its own SSH and user name . The user name is usually root. SSH consists of two parts: ip:port, and ip is the server IP address, port is the port number, this information is obtained when creating the virtual environment in step 2, we need to obtain this SSH connection for subsequent configuration needs to use:

(1) Configure the remote environment

Click Tools→Deployment→Cinfiguration        in the menu bar to enter the Deployment dialog box. (Because my Pycharm is Sinicized, the picture is displayed in Chinese)

(2) Establish an ssh connection

 In the Deployment dialog box, first click the plus sign to create a remote access service, select the SFTP protocol and click OK to create

 Set the server name (this can be named at will, it is best to write the name according to your own project)

(3) Configure SSH connection 

Click "..." on the right side of the SSH configuration to set the SSH content (set the remote connection host address, port, user name and password and other information.):

      Here we need to set three parameters: Host is the aforementioned remote server ip address xxx.xxx.xxx.xxx; Port is the port number after SSH connection; User name is the remote server user name, usually root

 After filling in the settings, you can click Test Connection to test the following connections. If successful, the result shown in the figure below will appear:

     When a prompt box appears, the connection is successful! Then click OK under the SSH Configurations dialog to return to the Deloyment dialog.   

     Next, in order to synchronize the content of the same project between the local and the server, we also need to set the project path mapping between the two.

4. Perform folder path mapping between local projects and remote projects

        In order to synchronize the content of the same project between the local and the server, we also need to set the project path mapping between the two, that is, the location where the local project is stored on the remote server.

     In the Deloyment dialog box, select Mappings to set the path mapping, and set the target path for local code synchronization to the cloud server. After setting, click OK to exit. The cloud server used here is Hengyuan Cloud, and the server deployment path is: /hy-tmp, as shown in the figure not shown.

 5. Set automatic upload project

After the connection is established and the path mapping between the local and remote projects is configured, we can set the automatic upload project. In the menu, click Tools→Deployment , and check Automatic Upload (always)【Auto upload (Always)] to ensure that the Python code can be automatically synchronized to the cloud server.

In this way, the project can be synchronized between the local and the server. At this time, after we update the local code, we only need to use the shortcut key (here is A) to save the code to complete the synchronization:

It should be noted here that if the automatic upload fails, we can manually upload the local project to the server (select Upload to above), and must upload and synchronize to the server in time after the local code is changed! ! Conversely, if the server modifies the code, pull the code from the server through the local Download from (download from...) to synchronize the local. 

Notice:

upload to ... As the name suggests, update the server code after changing the code.

download from Download the code from the server to the local.

Here we download the data from the server. select download from

He will ask you where to download from, select your server. Then wait for the download to complete.

But be careful, every time you modify the code, you must upload to... in the project to update the server code.

6. Verify that the connection is successful

After the SSH connection is established, you can verify whether the connection is successful by the method shown in the figure below:

 As shown in the figure below, after clicking to browse the remote host, you can see the file directory of the remote server on the right side of the local Pycharm, and you can see that it is exactly the same as the file directory of the remote server

2. Configure the Python interpreter locally

 At this point we can't use the server environment locally, we need to set the local Pycharm's Python interpreter to the Python interpreter in the specified environment in the remote server:

(1) Enter the settings and add the Python interpreter in the server to Pycharm:

 (2) Select the SSH interpreter, select SSH configuration, select the server connection set earlier, and then select ssh configuration:

 (3) Here you need to set the path mapping between the Python interpreter path in the remote server and the project, as shown in the following figure:

 At this point, our environment configuration work is complete! !

 After that, we upload the required files to the server, and then we can use the yolov5 model to train the data set on the remote server. If you adjust the training parameters, remember to upload to!

3. Start the server terminal locally

      Now we can use the working environment of the server locally, so how to open the server terminal locally, after all, other third-party libraries need to be packaged later (for example, yolov5 needs to run requirements.txt), here I also say:
        toolbar Open Tools (tools)->Start SSH Session (start ssh session), and then select the server we configured earlier to open the remote terminal at the local Terminal: 

Four, pay attention

If you want to switch back to the local working environment later, just go to the settings to switch the Python interpreter! ! !


This is the end of this remote server connection to the local Pycharm to run the yolov5 model tutorial. If you have any questions, you can leave a message in the comment area~

If it helps everyone, you can click three times + pay attention to support~

Guess you like

Origin blog.csdn.net/m0_57787115/article/details/130273543