Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sigmoid and exponential pool performance, accelerate with numpy #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,28 +212,28 @@ def _process_feats(self, output_reshaped, mask):
# descriptors:
def sigmoid(value):
"""Return the sigmoid of the input."""
return 1.0 / (1.0 + math.exp(-value))
return 1.0 / (1.0 + np.exp(-value))

def exponential(value):
"""Return the exponential of the input."""
return math.exp(value)
return np.exp(value)

# Vectorized calculation of above two functions:
sigmoid_v = np.vectorize(sigmoid)
exponential_v = np.vectorize(exponential)
#sigmoid_v = np.vectorize(sigmoid)
#exponential_v = np.vectorize(exponential)

grid_h, grid_w, _, _ = output_reshaped.shape

anchors = [self.anchors[i] for i in mask]

# Reshape to N, height, width, num_anchors, box_params:
anchors_tensor = np.reshape(anchors, [1, 1, len(anchors), 2])
box_xy = sigmoid_v(output_reshaped[..., :2])
box_wh = exponential_v(output_reshaped[..., 2:4]) * anchors_tensor
box_confidence = sigmoid_v(output_reshaped[..., 4])
box_xy = sigmoid(output_reshaped[..., :2])
box_wh = exponential(output_reshaped[..., 2:4]) * anchors_tensor
box_confidence = sigmoid(output_reshaped[..., 4])

box_confidence = np.expand_dims(box_confidence, axis=-1)
box_class_probs = sigmoid_v(output_reshaped[..., 5:])
box_class_probs = sigmoid(output_reshaped[..., 5:])

col = np.tile(np.arange(0, grid_w), grid_w).reshape(-1, grid_w)
row = np.tile(np.arange(0, grid_h).reshape(-1, 1), grid_h)
Expand Down