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

box_processing.py load_box_event function simplification #10

Open
grygry12345 opened this issue Nov 2, 2023 · 0 comments
Open

box_processing.py load_box_event function simplification #10

grygry12345 opened this issue Nov 2, 2023 · 0 comments

Comments

@grygry12345
Copy link

grygry12345 commented Nov 2, 2023

I checked your box_processing_differance.py. I find out the code complicated. So, I simplified.

def load_box_events(metadata, batch_start_time, duration):
    ending = metadata.get_ending()
    box_path = '_bbox.npy'.join(metadata.path.rsplit(ending, 1))
    box_events = np.load(box_path)

    # Filter out the events that are outside the desired time frame
    box_events = box_events[(box_events['t'] >= batch_start_time) & (box_events['t'] < batch_start_time + duration)]

    # Initialize the list to hold output event data
    out_list = []

    # Define the new class_ids for the features
    class_ids = {
        'face_bbox': 0, # Assuming 'face_bbox' is for face
        'x0y0': 1,      # Assuming 'x0y0' is for lip
        'x1y1': 2,      # Assuming 'x1y1' is for eye1
        'x2y2': 3,      # Assuming 'x2y2' is for eye2
        'x3y3': 4,      # Assuming 'x3y3' is for nose
        'x4y4': 5,      # Assuming 'x4y4' is for lips
    }

    # Define the dtype for the structured array
    out_dtype = np.dtype([
        ('t', '<i8'), ('x', '<f4'), ('y', '<f4'), ('w', '<f4'), ('h', '<f4'),
        ('class_id', '<u4'), ('track_id', '<u4'), ('class_confidence', '<f4')
    ])

    # Process each event and create a separate record for each feature
    for event in box_events:
        # First add the face bbox event
        face_bbox_event = (event['t'], event['x'], event['y'], event['w'], event['h'], class_ids['face_bbox'], event['track_id'], event['class_confidence'])
        out_list.append(face_bbox_event)
        
        # Now add the feature events
        for feature in ['x0y0', 'x1y1', 'x2y2', 'x3y3', 'x4y4']:
            class_id = class_ids[feature]
            x_key, y_key = feature[:2], feature[2:]
            feature_event = (event['t'], 
                             event[x_key] - ((event['w'] / 3) / 2), 
                             event[y_key] - ((event['h'] / 4) / 2),
                             event['w'] / 3, 
                             event['h'] / 4, 
                             class_id, 
                             event['track_id'], 
                             event['class_confidence'])
            out_list.append(feature_event)

    # Now convert out_list to a structured array
    out = np.array(out_list, dtype=out_dtype)

    return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant