Run the deep learning model from the paper on the server

foreword

First of all, you need to build a running environment on the server, see the previous blog: [ Building a deep learning model running environment on the server: ubuntu ]
This article mainly talks about how to run the open source model when the running environment is set up, using Inf-Net: Automatic COVID -19 Lung Infection Segmentation from CT Images this paper as an example.
I have downloaded the following parts locally and uploaded them to the server folder.
insert image description here

process and problems

  1. A MemoryError problem occurs when the second step of downloading is performed ;
    solution: pip --no-cache-dir install -r requirements.txt(Because pip's caching mechanism tries to cache the entire file of the library that you want to install in memory, and in an environment that limits the size of the cache, if the installation package is large, it will This error of MemoryError occurs.
    insert image description here

  2. It was only when I wrote this that I remembered that I did not install these libraries in the virtual environment !
    solution:

    • First activate the environment: source activate SINet( SINetfor the environment name
    • Note to switch to the folder path: cd /path( /paththe path of the file in the server
    • Then pip will do.
  3. Use it when downloading THOP pip install thopor it will fail.

  4. Switch to the corresponding directory when running python test.py.

Use XShell to connect to the server and run

Because the previous server did not have a GPU, I changed the server, set up the proxy first, and then used XShell to connect to the server, so the process is described below.

CondaHTTPError: HTTP 000 CONNECTION FAILED for url problem occurs when creating a virtual environment :

  1. Open the file for editing:vim ~/.condarc
  2. click ibutton
  3. Enter something to change
  4. click Escbutton
  5. Enter :wqto save and exit ( :qexit without saving)
  6. enterconda clean -i

run code

After downloading the code and dataset, you can start running the code.

Parameter problem :
parser.add_argument()You can add parameters for command line operation. For detailed usage, see: Python's parser.add_argument() usage - command line options, parameters and subcommands parser
t2.py:

import argparse
if __name__ == "__main__":
  parser = argparse.ArgumentParser()
  parser.add_argument('--aa', type=str, default = None)
  parser.add_argument('--bb', type=int, default=32)
  args = parser.parse_args()
  if(args.bb==3):
    print(f'hello world, args.bb={
      
      args.bb}')
  else:
    print(f'sorry, args.bb is not 3, but ={
      
      args.bb}')

Instructions:
python t2.py --aa=15 --bb=3
python t2.py --aa=15 --bb=10

Guess you like

Origin blog.csdn.net/qq_46056318/article/details/129371775