From 6665aa8c30e246ab33689e02a1757138140d2db4 Mon Sep 17 00:00:00 2001 From: Haodong Duan Date: Wed, 29 Dec 2021 21:45:30 +0800 Subject: [PATCH 1/4] update --- .pre-commit-config.yaml | 22 +++++++++++----------- mmaction/core/evaluation/ava_utils.py | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8608ff032..ad116805e8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,11 +29,11 @@ repos: args: ["--remove"] - id: mixed-line-ending args: ["--fix=lf"] - - repo: https://github.com/markdownlint/markdownlint - rev: v0.11.0 - hooks: - - id: markdownlint - args: [ "-r", "~MD002,~MD013,~MD024,~MD029,~MD033,~MD034,~MD036" ] + # - repo: https://github.com/markdownlint/markdownlint + # rev: v0.11.0 + # hooks: + # - id: markdownlint + # args: [ "-r", "~MD002,~MD013,~MD024,~MD029,~MD033,~MD034,~MD036" ] - repo: https://github.com/myint/docformatter rev: v1.3.1 hooks: @@ -44,9 +44,9 @@ repos: hooks: - id: codespell args: ["--skip", "*.ipynb,tools/data/hvu/label_map.json", "-L", "te,nd,thre,Gool,gool"] - - repo: https://github.com/open-mmlab/pre-commit-hooks - rev: v0.1.0 # Use the ref you want to point at - hooks: - - id: check-algo-readme - - id: check-copyright - args: ["mmaction", "tools", "tests"] # these directories will be checked + # - repo: https://github.com/open-mmlab/pre-commit-hooks + # rev: v0.1.0 # Use the ref you want to point at + # hooks: + # - id: check-algo-readme + # - id: check-copyright + # args: ["mmaction", "tools", "tests"] # these directories will be checked diff --git a/mmaction/core/evaluation/ava_utils.py b/mmaction/core/evaluation/ava_utils.py index 7f6571d478..e7aa10b2f6 100644 --- a/mmaction/core/evaluation/ava_utils.py +++ b/mmaction/core/evaluation/ava_utils.py @@ -1,6 +1,6 @@ # This piece of code is directly adapted from ActivityNet official repo # https://github.com/activitynet/ActivityNet/blob/master/ -# Evaluation/get_ava_performance.py. Some unused codes are removed. +# Evaluation/get_ava_performance.py. Some unused codes are removed. import csv import logging import time From 05c3632217659fc6b582b2d0b283569b67589e87 Mon Sep 17 00:00:00 2001 From: Haodong Duan Date: Wed, 29 Dec 2021 21:46:44 +0800 Subject: [PATCH 2/4] update --- mmaction/apis/train.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mmaction/apis/train.py b/mmaction/apis/train.py index f04ed6c712..f0557cfc97 100644 --- a/mmaction/apis/train.py +++ b/mmaction/apis/train.py @@ -1,5 +1,6 @@ # Copyright (c) OpenMMLab. All rights reserved. import copy as cp +import os import os.path as osp import numpy as np @@ -205,21 +206,24 @@ def train_model(model, if test['test_last'] or test['test_best']: best_ckpt_path = None if test['test_best']: - if hasattr(eval_hook, 'best_ckpt_path'): - best_ckpt_path = eval_hook.best_ckpt_path - - if best_ckpt_path is None or not osp.exists(best_ckpt_path): + assert eval_hook is not None + best_ckpt_path = None + ckpt_paths = [x for x in os.listdir(cfg.work_dir) if 'best' in x] + ckpt_paths = [x for x in ckpt_paths if x.endswith('.pth')] + if len(ckpt_paths) == 0: + runner.logger.info('Warning: test_best set, but no ckpt found') test['test_best'] = False - if best_ckpt_path is None: - runner.logger.info('Warning: test_best set as True, but ' - 'is not applicable ' - '(eval_hook.best_ckpt_path is None)') - else: - runner.logger.info('Warning: test_best set as True, but ' - 'is not applicable (best_ckpt ' - f'{best_ckpt_path} not found)') if not test['test_last']: return + elif len(ckpt_paths) > 1: + epoch_ids = [ + int(x.split('epoch_')[-1][:-4]) for x in ckpt_paths + ] + best_ckpt_path = ckpt_paths[np.argmax(epoch_ids)] + else: + best_ckpt_path = ckpt_paths[0] + if best_ckpt_path: + best_ckpt_path = osp.join(cfg.work_dir, best_ckpt_path) test_dataset = build_dataset(cfg.data.test, dict(test_mode=True)) gpu_collect = cfg.get('evaluation', {}).get('gpu_collect', False) From af0657ddcac3d65bddd2ba0b078db5987345cbdc Mon Sep 17 00:00:00 2001 From: Haodong Duan Date: Wed, 29 Dec 2021 21:47:25 +0800 Subject: [PATCH 3/4] revert --- .pre-commit-config.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ad116805e8..f8608ff032 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,11 +29,11 @@ repos: args: ["--remove"] - id: mixed-line-ending args: ["--fix=lf"] - # - repo: https://github.com/markdownlint/markdownlint - # rev: v0.11.0 - # hooks: - # - id: markdownlint - # args: [ "-r", "~MD002,~MD013,~MD024,~MD029,~MD033,~MD034,~MD036" ] + - repo: https://github.com/markdownlint/markdownlint + rev: v0.11.0 + hooks: + - id: markdownlint + args: [ "-r", "~MD002,~MD013,~MD024,~MD029,~MD033,~MD034,~MD036" ] - repo: https://github.com/myint/docformatter rev: v1.3.1 hooks: @@ -44,9 +44,9 @@ repos: hooks: - id: codespell args: ["--skip", "*.ipynb,tools/data/hvu/label_map.json", "-L", "te,nd,thre,Gool,gool"] - # - repo: https://github.com/open-mmlab/pre-commit-hooks - # rev: v0.1.0 # Use the ref you want to point at - # hooks: - # - id: check-algo-readme - # - id: check-copyright - # args: ["mmaction", "tools", "tests"] # these directories will be checked + - repo: https://github.com/open-mmlab/pre-commit-hooks + rev: v0.1.0 # Use the ref you want to point at + hooks: + - id: check-algo-readme + - id: check-copyright + args: ["mmaction", "tools", "tests"] # these directories will be checked From 5ff54affca25ecb5a647548046a22d52f100e29c Mon Sep 17 00:00:00 2001 From: Haodong Duan Date: Wed, 29 Dec 2021 21:49:55 +0800 Subject: [PATCH 4/4] update --- mmaction/apis/train.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mmaction/apis/train.py b/mmaction/apis/train.py index f0557cfc97..7a3cd1351b 100644 --- a/mmaction/apis/train.py +++ b/mmaction/apis/train.py @@ -206,8 +206,6 @@ def train_model(model, if test['test_last'] or test['test_best']: best_ckpt_path = None if test['test_best']: - assert eval_hook is not None - best_ckpt_path = None ckpt_paths = [x for x in os.listdir(cfg.work_dir) if 'best' in x] ckpt_paths = [x for x in ckpt_paths if x.endswith('.pth')] if len(ckpt_paths) == 0: @@ -246,7 +244,7 @@ def train_model(model, if test['test_last']: names.append('last') ckpts.append(None) - if test['test_best']: + if test['test_best'] and best_ckpt_path is not None: names.append('best') ckpts.append(best_ckpt_path)