Publishing 2019 R1 content
[platform/upstream/dldt.git] / tools / accuracy_checker / accuracy_checker / annotation_converters / _reid_common.py
1 """
2 Copyright (c) 2019 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 """
16
17 from pathlib import Path
18
19 from ..representation import ReIdentificationAnnotation
20
21
22 def read_directory(directory, query, image_pattern):
23     pids = set()
24     images = []
25     for image in directory.glob("*.jpg"):
26         pid, camid = map(int, image_pattern.search(image.name).groups())
27         if pid == -1:
28             continue
29
30         camid -= 1
31         pids.add(pid)
32
33         identifier = str(Path(directory.name) / image.name)
34         images.append(ReIdentificationAnnotation(identifier, camid, pid, query))
35
36     return images, pids
37
38
39 def check_dirs(dirs, parent_dir, arg_name='data_dir'):
40     for directory in dirs:
41         if directory.is_dir():
42             continue
43
44         message_pattern = "{directory} not found in {parent_dir}. Check {arg_name} is pointed to a correct directory"
45         raise FileNotFoundError(message_pattern.format(directory=directory, parent_dir=parent_dir, arg_name=arg_name))