-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.py
48 lines (40 loc) · 1.1 KB
/
misc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import operator
import sys
import numpy as np
import os
from enum import Enum
import json
class BBType(Enum):
"""
Class representing if the bounding box is groundtruth or not.
"""
GROUND_TRUTH = 1
DETECTED = 2
class EndoCV_misc:
def error(msg):
print(msg)
sys.exit(0)
def is_float_between_0_and_1(value):
"""
function to check if the number is a float between 0.0 and 1.0
"""
try:
val = float(value)
if val > 0.0 and val < 1.0:
return True
else:
return False
except ValueError:
return False
def file_lines_to_list(path):
with open(path) as f:
content = f.readlines()
content = [x.strip() for x in content]
return content
def get_file_name_only(file_path):
if file_path is None:
return ''
return os.path.splitext(os.path.basename(file_path))[0]
def write2json(json_name, data):
with open(json_name, 'w') as f:
json.dump(data, f)