Reconstruct the directory structure

This commit is contained in:
darkliang
2022-04-12 13:44:07 +08:00
parent 213b3a658f
commit 28f50410a5
32 changed files with 162 additions and 45 deletions
File diff suppressed because it is too large Load Diff
+26
View File
@@ -0,0 +1,26 @@
# HID Tutorial
![](http://hid2022.iapr-tc4.org/wp-content/uploads/sites/7/2022/03/%E5%9B%BE%E7%89%871-2.png)
This is the official support for competition of [Human Identification at a Distance (HID)](http://hid2022.iapr-tc4.org/). We report our result of 68.7% using the baseline model and 80.0% with re-ranking. In order for participants to better start the first step, we provide a tutorial on how to use OpenGait for HID.
## Preprocess the dataset
Download the raw dataset from the [official link](http://hid2022.iapr-tc4.org/). You will get three compressed files, i.e. `train.tar`, `HID2022_test_gallery.zip` and `HID2022_test_probe.zip`.
After unpacking these three files, run this command:
```shell
python misc/HID/pretreatment_HID.py --input_train_path="train" --input_gallery_path="HID2022_test_gallery" --input_probe_path="HID2022_test_probe" --output_path="HID-128-pkl"
```
## Train the dataset
Modify the `dataset_root` in `./misc/HID/baseline_hid.yaml`, and then run this command:
```shell
CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./misc/HID/baseline_hid.yaml --phase train
```
You can also download the [trained model](https://github.com/ShiqiYu/OpenGait/releases/download/v1.1/pretrained_hid_model.zip) and place it in `output` after unzipping.
## Get the submission file
```shell
CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./misc/HID/baseline_hid.yaml --phase test
```
The result will be generated in your working directory.
## Submit the result
Follow the steps in the [official submission guide](https://codalab.lisn.upsaclay.fr/competitions/2542#participate), you need rename the file to `submission.csv` and compress it to a zip file. Finally, you can upload the zip file to the [official submission link](https://codalab.lisn.upsaclay.fr/competitions/2542#participate-submit_results).
+123
View File
@@ -0,0 +1,123 @@
import os
import cv2
import numpy as np
import argparse
import pickle
from tqdm import tqdm
parser = argparse.ArgumentParser(description='Test')
parser.add_argument('--input_train_path', default='', type=str,
help='Root path of train.')
parser.add_argument('--input_gallery_path', default='', type=str,
help='Root path of gallery.')
parser.add_argument('--input_probe_path', default='', type=str,
help='Root path of probe.')
parser.add_argument('--output_path', default='', type=str,
help='Root path for output.')
opt = parser.parse_args()
OUTPUT_PATH = opt.output_path
print('Pretreatment Start.\n'
'Input train path: {}\n'
'Input gallery path: {}\n'
'Input probe path: {}\n'
'Output path: {}\n'.format(
opt.input_train_path, opt.input_gallery_path, opt.input_probe_path, OUTPUT_PATH))
INPUT_PATH = opt.input_train_path
print("Walk the input train path")
id_list = os.listdir(INPUT_PATH)
id_list.sort()
for _id in tqdm(id_list):
seq_type = os.listdir(os.path.join(INPUT_PATH, _id))
seq_type.sort()
for _seq_type in seq_type:
out_dir = os.path.join(OUTPUT_PATH, _id, _seq_type, "default")
count_frame = 0
all_imgs = []
frame_list = sorted(os.listdir(
os.path.join(INPUT_PATH, _id, _seq_type)))
for _frame_name in frame_list:
frame_path = os.path.join(
INPUT_PATH, _id, _seq_type, _frame_name)
img = cv2.imread(frame_path, cv2.IMREAD_GRAYSCALE)
if img is not None:
# Save the img
all_imgs.append(img)
count_frame += 1
all_imgs = np.asarray(all_imgs)
if count_frame > 0:
os.makedirs(out_dir, exist_ok=True)
all_imgs_pkl = os.path.join(out_dir, '{}.pkl'.format(_seq_type))
pickle.dump(all_imgs, open(all_imgs_pkl, 'wb'))
# Warn if the sequence contains less than 5 frames
if count_frame < 5:
print('Seq:{}-{}, less than 5 valid data.'.format(_id, _seq_type))
print("Walk the input gallery path")
INPUT_PATH = opt.input_gallery_path
id_list = os.listdir(INPUT_PATH)
id_list.sort()
for _id in tqdm(id_list):
seq_type = os.listdir(os.path.join(INPUT_PATH, _id))
seq_type.sort()
for _seq_type in seq_type:
out_dir = os.path.join(OUTPUT_PATH, _id, _seq_type, "default")
count_frame = 0
all_imgs = []
frame_list = sorted(os.listdir(
os.path.join(INPUT_PATH, _id, _seq_type)))
for _frame_name in frame_list:
frame_path = os.path.join(
INPUT_PATH, _id, _seq_type, _frame_name)
img = cv2.imread(frame_path, cv2.IMREAD_GRAYSCALE)
if img is not None:
# Save the img
all_imgs.append(img)
count_frame += 1
all_imgs = np.asarray(all_imgs)
if count_frame > 0:
os.makedirs(out_dir, exist_ok=True)
all_imgs_pkl = os.path.join(out_dir, '{}.pkl'.format(_seq_type))
pickle.dump(all_imgs, open(all_imgs_pkl, 'wb'))
# Warn if the sequence contains less than 5 frames
if count_frame < 5:
print('Seq:{}-{}, less than 5 valid data.'.format(_id, _seq_type))
print("Finish {}".format(_id))
print("Walk the input probe path")
INPUT_PATH = opt.input_probe_path
seq_type = os.listdir(INPUT_PATH)
seq_type.sort()
_id = "probe"
for _seq_type in tqdm(seq_type):
out_dir = os.path.join(OUTPUT_PATH, _id, _seq_type, "default")
count_frame = 0
all_imgs = []
frame_list = sorted(os.listdir(
os.path.join(INPUT_PATH, _seq_type)))
for _frame_name in frame_list:
frame_path = os.path.join(
INPUT_PATH, _seq_type, _frame_name)
img = cv2.imread(frame_path, cv2.IMREAD_GRAYSCALE)
if img is not None:
# Save the img
all_imgs.append(img)
count_frame += 1
all_imgs = np.asarray(all_imgs)
if count_frame > 0:
os.makedirs(out_dir, exist_ok=True)
all_imgs_pkl = os.path.join(out_dir, '{}.pkl'.format(_seq_type))
pickle.dump(all_imgs, open(all_imgs_pkl, 'wb'))
# Warn if the sequence contains less than 5 frames
if count_frame < 5:
print('Seq:{}-{}, less than 5 valid data.'.format(_id, _seq_type))