python : improved documentation
This commit is contained in:
@ -18,7 +18,7 @@ else:
|
||||
|
||||
@njit('uint8[:, :, :, :](uint16, uint16)')
|
||||
def build_features(width: int, height: int) -> np.ndarray:
|
||||
"""Initialize the features base on the input shape.
|
||||
"""Initialize the features based on the input shape.
|
||||
|
||||
Args:
|
||||
shape (Tuple[int, int]): Shape of the image (Width, Height)
|
||||
@ -90,9 +90,31 @@ def classify_weak_clf(x_feat_i: np.ndarray, threshold: int, polarity: int) -> np
|
||||
res[polarity * x_feat_i < polarity * threshold] = 1
|
||||
return res
|
||||
|
||||
@njit('uint8[:](float64[:], int32[:, :], int32[:, :])')
|
||||
def classify_viola_jones(alphas: np.ndarray, classifiers: np.ndarray, X_feat: np.ndarray) -> np.ndarray:
|
||||
"""Classify the trained classifiers on the given features.
|
||||
|
||||
Args:
|
||||
alphas (np.ndarray): Trained alphas
|
||||
classifiers (np.ndarray): Trained classifiers
|
||||
X_feat (np.ndarray): Integrated features
|
||||
|
||||
Returns:
|
||||
np.ndarray: Classification results
|
||||
"""
|
||||
total = np.zeros(X_feat.shape[1], dtype = np.float64)
|
||||
|
||||
for i, alpha in enumerate(tqdm_iter(alphas, "Classifying ViolaJones")):
|
||||
(j, threshold, polarity) = classifiers[i]
|
||||
total += alpha * classify_weak_clf(X_feat[j], threshold, polarity)
|
||||
|
||||
y_pred = np.zeros(X_feat.shape[1], dtype = np.uint8)
|
||||
y_pred[total >= 0.5 * np.sum(alphas)] = 1
|
||||
return y_pred
|
||||
|
||||
@njit('Tuple((int32, float64, float64[:]))(int32[:, :], float64[:], int32[:, :], uint8[:])')
|
||||
def select_best(classifiers: np.ndarray, weights: np.ndarray, X_feat: np.ndarray, y: np.ndarray) -> Tuple[int, float, np.ndarray]:
|
||||
"""Select the best classifier given theirs predictions.
|
||||
"""Select the best classifier given their predictions.
|
||||
|
||||
Args:
|
||||
classifiers (np.ndarray): The weak classifiers
|
||||
@ -139,28 +161,6 @@ def train_viola_jones(T: int, X_feat: np.ndarray, X_feat_argsort: np.ndarray, y:
|
||||
|
||||
return alphas, final_classifier
|
||||
|
||||
@njit('uint8[:](float64[:], int32[:, :], int32[:, :])')
|
||||
def classify_viola_jones(alphas: np.ndarray, classifiers: np.ndarray, X_feat: np.ndarray) -> np.ndarray:
|
||||
"""Classify the trained classifiers on the given features.
|
||||
|
||||
Args:
|
||||
alphas (np.ndarray): Trained alphas
|
||||
classifiers (np.ndarray): Trained classifiers
|
||||
X_feat (np.ndarray): Integrated features
|
||||
|
||||
Returns:
|
||||
np.ndarray: Classification results
|
||||
"""
|
||||
total = np.zeros(X_feat.shape[1], dtype = np.float64)
|
||||
|
||||
for i, alpha in enumerate(tqdm_iter(alphas, "Classifying ViolaJones")):
|
||||
(j, threshold, polarity) = classifiers[i]
|
||||
total += alpha * classify_weak_clf(X_feat[j], threshold, polarity)
|
||||
|
||||
y_pred = np.zeros(X_feat.shape[1], dtype = np.uint8)
|
||||
y_pred[total >= 0.5 * np.sum(alphas)] = 1
|
||||
return y_pred
|
||||
|
||||
#@njit
|
||||
#def get_best_anova_features(X: np.ndarray, y: np.ndarray) -> np.ndarray:
|
||||
# #SelectPercentile(f_classif, percentile = 10).fit(X, y).get_support(indices = True)
|
||||
|
Reference in New Issue
Block a user