- prediction/image/ FastAPI 서버 Docker 환경 구성 - Dockerfile: PyTorch 2.1 + CUDA 12.1 기반 GPU 이미지 - docker-compose.yml: GPU 할당 + 데이터 볼륨 마운트 - requirements.txt: 서버 의존성 목록 - .env.example: 환경변수 템플릿 - DOCKER_USAGE.md: 빌드/실행/API 사용법 문서 - Dockerfile에 .dockerignore 제외 폴더 mkdir -p 추가 - .gitignore: prediction/image 결과물 및 모델 가중치(.pth) 제외 추가 - dbInsert_csv.py, dbInsert_shp.py 삭제 (미사용 DB 로직) - api.py: dbInsert import 및 주석 처리된 DB 호출 코드 제거 - aerialRouter.ts: req.params 타입 오류 수정
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
# Copyright (c) OpenMMLab. All rights reserved.
|
|
import argparse
|
|
|
|
from mmcv import Config
|
|
from mmcv.cnn import get_model_complexity_info
|
|
|
|
from mmseg.models import build_segmentor
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(
|
|
description='Get the FLOPs of a segmentor')
|
|
parser.add_argument('config', help='train config file path')
|
|
parser.add_argument(
|
|
'--shape',
|
|
type=int,
|
|
nargs='+',
|
|
default=[2048, 1024],
|
|
help='input image size')
|
|
args = parser.parse_args()
|
|
return args
|
|
|
|
|
|
def main():
|
|
|
|
args = parse_args()
|
|
|
|
if len(args.shape) == 1:
|
|
input_shape = (3, args.shape[0], args.shape[0])
|
|
elif len(args.shape) == 2:
|
|
input_shape = (3, ) + tuple(args.shape)
|
|
else:
|
|
raise ValueError('invalid input shape')
|
|
|
|
cfg = Config.fromfile(args.config)
|
|
cfg.model.pretrained = None
|
|
model = build_segmentor(
|
|
cfg.model,
|
|
train_cfg=cfg.get('train_cfg'),
|
|
test_cfg=cfg.get('test_cfg')).cuda()
|
|
model.eval()
|
|
|
|
if hasattr(model, 'forward_dummy'):
|
|
model.forward = model.forward_dummy
|
|
else:
|
|
raise NotImplementedError(
|
|
'FLOPs counter is currently not currently supported with {}'.
|
|
format(model.__class__.__name__))
|
|
|
|
flops, params = get_model_complexity_info(model, input_shape)
|
|
split_line = '=' * 30
|
|
print('{0}\nInput shape: {1}\nFlops: {2}\nParams: {3}\n{0}'.format(
|
|
split_line, input_shape, flops, params))
|
|
print('!!!Please be cautious if you use the results in papers. '
|
|
'You may need to check if all ops are supported and verify that the '
|
|
'flops computation is correct.')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|