init commit of samurai

This commit is contained in:
Cheng-Yen Yang
2024-11-19 22:12:54 -08:00
parent f65f4ba181
commit c17e4cecc0
679 changed files with 123982 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
import numpy as np
import pandas as pd
def load_text_numpy(path, delimiter, dtype):
if isinstance(delimiter, (tuple, list)):
for d in delimiter:
try:
ground_truth_rect = np.loadtxt(path, delimiter=d, dtype=dtype)
return ground_truth_rect
except:
pass
raise Exception('Could not read file {}'.format(path))
else:
ground_truth_rect = np.loadtxt(path, delimiter=delimiter, dtype=dtype)
return ground_truth_rect
def load_text_pandas(path, delimiter, dtype):
if isinstance(delimiter, (tuple, list)):
for d in delimiter:
try:
ground_truth_rect = pd.read_csv(path, delimiter=d, header=None, dtype=dtype, na_filter=False,
low_memory=False).values
return ground_truth_rect
except Exception as e:
pass
raise Exception('Could not read file {}'.format(path))
else:
ground_truth_rect = pd.read_csv(path, delimiter=delimiter, header=None, dtype=dtype, na_filter=False,
low_memory=False).values
return ground_truth_rect
def load_text(path, delimiter=' ', dtype=np.float32, backend='numpy'):
if backend == 'numpy':
return load_text_numpy(path, delimiter, dtype)
elif backend == 'pandas':
return load_text_pandas(path, delimiter, dtype)
def load_str(path):
with open(path, "r") as f:
text_str = f.readline().strip().lower()
return text_str