cvat-ai / cvat

Annotate better with CVAT, the industry-leading data engine for machine learning. Used and trusted by teams at any scale, for data of any scale.
https://cvat.ai
MIT License
12.23k stars 2.95k forks source link

成功解决linux服务器部署SAM时出现一些bug #8341

Closed zhanghaihangandliuli closed 2 weeks ago

zhanghaihangandliuli commented 3 weeks ago

Actions before raising this issue

Steps to Reproduce

当我在serverless文件夹下使用 sudo nuctl deploy --project-name cvat --path "pwd/pytorch/facebookresearch/sam/nuclio/" --file "pwd/pytorch/facebookresearch/sam/nuclio/function.yaml" --platform local时 但是出现下载超时的bug

 > [ 4/13] RUN pip3 install torch torchvision torchaudio opencv-python pycocotools matplotlib onnxruntime onnx:
665.5     for chunk in response.raw.stream(
665.5   File "/usr/lib/python3/dist-packages/pip/_vendor/urllib3/response.py", line 576, in stream
665.5     data = self.read(amt=amt, decode_content=decode_content)
665.5   File "/usr/lib/python3/dist-packages/pip/_vendor/urllib3/response.py", line 512, in read
665.5     with self._error_catcher():
665.5   File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
665.5     self.gen.throw(typ, value, traceback)
665.5   File "/usr/lib/python3/dist-packages/pip/_vendor/urllib3/response.py", line 443, in _error_catcher
665.5     raise ReadTimeoutError(self._pool, None, "Read timed out.")
665.5 pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
------
Dockerfile.processor:24
--------------------
  22 |     RUN apt-get update && apt-get -y install curl git python3 python3-pip ffmpeg libsm6 libxext6
  23 |     
  24 | >>> RUN pip3 install torch torchvision torchaudio opencv-python pycocotools matplotlib onnxruntime onnx -i 
  25 |     
  26 |     RUN pip3 install git+https://github.com/facebookresearch/segment-anything.git
--------------------
ERROR: failed to solve: process "/bin/sh -c pip3 install torch torchvision torchaudio opencv-python pycocotools matplotlib onnxruntime onnx" did not complete successfully: exit code: 2

    /nuclio/pkg/cmdrunner/shellrunner.go:114
Failed to build
    /nuclio/pkg/dockerclient/shell.go:116
Failed to build docker image
    .../pkg/containerimagebuilderpusher/docker.go:70
Failed to build processor image
    /nuclio/pkg/processor/build/builder.go:264
Failed to deploy function
    ...//nuclio/pkg/platform/abstract/platform.go:227

Expected Behavior

img_v3_02e1_88b3d3e9-338c-41ae-8683-c299fe1e374g

Possible Solution

于是我换了清华的镜像,但是还是没有效果。最后我将function.yaml的文件内容修改成这样的,就成功运行

# Copyright (C) 2023-2024 CVAT.ai Corporation
#
# SPDX-License-Identifier: MIT

metadata:
  name: pth-facebookresearch-sam-vit-h
  namespace: cvat
  annotations:
    name: Segment Anything
    version: 2
    type: interactor
    spec:
    min_pos_points: 0
    min_neg_points: 0
    startswith_box_optional: true
    animated_gif: https://raw.githubusercontent.com/cvat-ai/cvat/develop/site/content/en/images/hrnet_example.gif
    help_message: The interactor allows to get a mask of an object using at least one positive, and any negative points inside it

spec:
  description: Interactive object segmentation with Segment-Anything
  runtime: 'python:3.8'
  handler: main:handler
  eventTimeout: 30s
  env:
    - name: PYTHONPATH
      value: /opt/nuclio/sam

  build:
    image: cvat.pth.facebookresearch.sam.vit_h
    baseImage: ubuntu:22.04

    directives:
      preCopy:
      # disable interactive frontend
        - kind: ENV
          value: DEBIAN_FRONTEND=noninteractive
      # set workdir
        - kind: WORKDIR
          value: /opt/nuclio/sam
      # install basic deps
        - kind: RUN
          value: apt-get update && apt-get -y install curl git python3 python3-pip ffmpeg libsm6 libxext6
      # install sam deps
        - kind: RUN
          value: pip3 install torch torchvision torchaudio pycocotools matplotlib onnxruntime onnx -i  https://pypi.tuna.tsinghua.edu.cn/simple/ 
      # install sam code
        - kind: RUN
        #   value: pip3 install git+https://github.com/facebookresearch/segment-anything.git 
          value: pip3 install --default-timeout=10000 git+https://github.com/facebookresearch/segment-anything.git
      # download sam weights
        - kind: RUN
        #   value: curl -O https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
          value: curl -O --retry 5 --retry-delay 10000 https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth
      # map pip3 and python3 to pip and python
        - kind: RUN
          value: ln -s /usr/bin/pip3 /usr/local/bin/pip && ln -s /usr/bin/python3 /usr/bin/python
  triggers:
    myHttpTrigger:
      maxWorkers: 2
      kind: 'http'
      workerAvailabilityTimeoutMilliseconds: 10000
      attributes:
        maxRequestBodySize: 33554432 # 32MB

  platform:
    attributes:
      restartPolicy:
        name: always
        maximumRetryCount: 3
      mountMode: volume

Context

当我再次运行: sudo nuctl deploy --project-name cvat --path "pwd/pytorch/facebookresearch/sam/nuclio/" --file "pwd/pytorch/facebookresearch/sam/nuclio/function.yaml" --platform local时 nuclio面板出现 img_v3_02e1_4c46fe1e-e3fe-49c5-bf7f-cc3e111fe28g 应该是成功了

Environment

我使用的是腾讯云linux服务器
azhavoro commented 3 weeks ago

665.5 pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

Unable to reproduce, make sure you have no problems connecting to files.pythonhosted.org.

goodluck2q commented 2 weeks ago

image image

azhavoro commented 2 weeks ago

I hope the issue is resolved