U ^ 2-Net HTTP es un contenedor de servicio HTTP del modelo: U ^ 2-Net: Profundizando con estructura en U anidada para la detección de objetos salientes (Qin et al, Pattern Recognition 2020)
Requisitos:
Python> = 3.6
pytorch ( Cómo instalar pytorch en Windows )
Paso 1:
Resultado:
1 2 3 4 5 6 7 8 | Administrator@REL0CC1I7V27L7B MINGW64 /d/Python $ git clone https://github.com/cyrildiagne/u2net-http.git Cloning into 'u2net-http'... remote: Enumerating objects: 23, done. remote: Counting objects: 100% (23/23), done. remote: Compressing objects: 100% (22/22), done. remote: Total 23 (delta 6), reused 13 (delta 0), pack-reused 0 Unpacking objects: 100% (23/23), done. |
Paso 2:
1 2 | cd u2net-http git clone https://github.com/NathanUA/U-2-Net.git |
Resultado:
1 2 3 4 5 6 7 | Administrator@REL0CC1I7V27L7B MINGW64 /d/Python/u2net-http (master) $ git clone https://github.com/NathanUA/U-2-Net.git Cloning into 'U-2-Net'... remote: Enumerating objects: 247, done. remote: Total 247 (delta 0), reused 0 (delta 0), pack-reused 247 Receiving objects: 100% (247/247), 8.26 MiB | 1.81 MiB/s, done. Resolving deltas: 100% (101/101), done. |
Paso 4:
Descargue u2netp.pth (4.7 MB) a ./U-2-Net/saved_models/u2netp/
Paso 5:
Edite el archivo u2net.py
Línea 22:
1 | # from model import U2NETP # small version u2net 4.7 MB |
a
1 | from model import U2NETP # small version u2net 4.7 MB |
Línea 24:
1 | model_dir = './U-2-Net/saved_models/u2net/u2net.pth' |
a:
1 | model_dir = './U-2-Net/saved_models/u2netp/u2netp.pth' |
Línea 27:
1 | net = U2NET( 3 , 1 ) |
a:
1 | net = U2NETP( 3 , 1 ) |
Paso 6:
1 2 3 4 5 6 7 8 | pip install Flask==1.1.1 pip install flask-cors==3.0.8 pip install gunicorn==19.9.0 pip install numpy==1.15.2 pip install scikit-image==0.14.0 pip install Pillow==6.2.2 pip install scipy pip install matplotlib |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 dieciséis 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | D:\Python\u2net-http>pip install scipy Collecting scipy Downloading scipy-1.5.2-cp37-cp37m-win_amd64.whl (31.2 MB) |████████████████████████████████| 31.2 MB 121 kB/s Requirement already satisfied: numpy>=1.14.5 in c:\users\administrator\appdata\l ocal\programs\python\python37\lib\site-packages (from scipy) (1.15.2) Installing collected packages: scipy Successfully installed scipy-1.5.2 D:\Python\u2net-http>pip install matplotlib Collecting matplotlib Downloading matplotlib-3.3.1-cp37-cp37m-win_amd64.whl (8.5 MB) |████████████████████████████████| 8.5 MB 3.3 MB/s Requirement already satisfied: numpy>=1.15 in c:\users\administrator\appdata\loc al\programs\python\python37\lib\site-packages (from matplotlib) (1.15.2) Collecting cycler>=0.10 Downloading cycler-0.10.0-py2.py3-none-any.whl (6.5 kB) Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB) |████████████████████████████████| 67 kB 622 kB/s Collecting kiwisolver>=1.0.1 Downloading kiwisolver-1.2.0-cp37-none-win_amd64.whl (57 kB) |████████████████████████████████| 57 kB 295 kB/s Collecting python-dateutil>=2.1 Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB) |████████████████████████████████| 227 kB 6.4 MB/s Collecting certifi>=2020.06.20 Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB) |████████████████████████████████| 156 kB 3.2 MB/s Requirement already satisfied: pillow>=6.2.0 in c:\users\administrator\appdata\l ocal\programs\python\python37\lib\site-packages (from matplotlib) (6.2.2) Requirement already satisfied: six in c:\users\administrator\appdata\local\progr ams\python\python37\lib\site-packages (from cycler>=0.10->matplotlib) (1.15.0) Installing collected packages: cycler, pyparsing, kiwisolver, python-dateutil, c ertifi, matplotlib Successfully installed certifi-2020.6.20 cycler-0.10.0 kiwisolver-1.2.0 matplotl ib-3.3.1 pyparsing-2.4.7 python-dateutil-2.8.1 |
Paso 7: para dispositivos que no son CUDA
Editar archivo u2net.py
Cambiar líneas:
1 2 3 | net.load_state_dict(torch.load(model_dir)) if torch.cuda.is_available(): net.cuda() |
a:
1 2 3 4 5 | if torch.cuda.is_available(): net.load_state_dict(torch.load(model_dir)) net.cuda() else : net.load_state_dict(torch.load(model_dir,map_location = 'cpu' )) |
Paso 8: ejecutar el servidorpython main.py
1 2 3 4 5 6 7 8 9 10 | D:\Python\u2net-http>python main.py Loading U-2-Net... * Serving Flask app "main" (lazy loading) * Environment: development * Debug mode: on INFO:werkzeug: * Restarting with stat Loading U-2-Net... WARNING:werkzeug: * Debugger is active! INFO:werkzeug: * Debugger PIN: 254-112-049 INFO:werkzeug: * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit) |
Ejemplo:
1 2 3 4 5 | Administrator@REL0CC1I7V27L7B MINGW64 ~/Desktop $ curl -F "data=@picture.jpg" http://localhost:8080 -o result.png % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 152k 100 15566 100 137k 3488 31452 0:00:04 0:00:04 --:--:-- 31452 |
0 Comentarios
Dejanos tu comentario para seguir mejorando!