Skip to content

Commit

Permalink
skip frames on edge
Browse files Browse the repository at this point in the history
  • Loading branch information
gferraro committed Oct 3, 2024
1 parent a34b205 commit 8d12239
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ def main():
"tag_precedence": config.build.tag_precedence,
"min_mass": master_dataset.min_frame_mass,
"thermal_diff_norm": config.build.thermal_diff_norm,
"filter_by_lq": master_dataset.filter_by_lq,
}
)
create_tf_records(
Expand Down
55 changes: 39 additions & 16 deletions src/ml_tools/datasetstructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(
human_tags=None,
remapped_lbl=None,
mega_missed_regions=None,
skip_ffc=True,
):
# regions that megadetector found nothing in
self.mega_missed_regions = mega_missed_regions
Expand Down Expand Up @@ -173,12 +174,8 @@ def __init__(
self.frame_crop = None
self.num_frames = num_frames
self.important_predicted = 0

mass_history = np.uint16(
[region.mass for region in self.regions_by_frame.values()]
)
mass_history = [
region.frame_number
region.mass
for region in self.regions_by_frame.values()
if region.mass > 0
and (
Expand Down Expand Up @@ -243,29 +240,55 @@ def add_sample(self, sample):
def calculate_sample_frames(
self, min_mass=None, max_mass=None, ffc_frames=None, skip_last=None
):
crop_rectangle = Rectangle(2, 2, 160 - 2 * 2, 140 - 2 * 2)

logging.debug(
"Calculating sample with min %s and max %s ffc %s and skip %s",
min_mass,
max_mass,
ffc_frames,
skip_last,
)
frame_numbers = list(self.regions_by_frame.keys())
previous_mass = None

if skip_last is not None:
skip_x = int(len(frame_numbers) * skip_last)
frame_numbers = frame_numbers[:-skip_x]
frame_numbers = [
frame
for frame in frame_numbers
if (ffc_frames is None or frame not in ffc_frames)
and (
self.mega_missed_regions is None
or frame not in self.mega_missed_regions
)
]
frame_numbers.sort()

frame_numbers.sort()
for frame_num in frame_numbers:
region = self.regions_by_frame[frame_num]
if region.mass == 0 or region.blank:

if (
region.mass == 0
or region.blank
or region.width <= 0
or region.height <= 0
):
continue
if ffc_frames is not None and frame_num in ffc_frames:
continue

if (
self.mega_missed_regions is not None
and frame_num in self.mega_missed_regions
):
continue

if min_mass is not None and region.mass < min_mass:
continue
if max_mass is not None and region.mass > max_mass:
continue
# dont use regions on the edge if the mass deviates too much from the last known good mass
region.set_is_along_border(crop_rectangle)
if region.is_along_border:
if previous_mass is not None:
previous_mass_thresh = previous_mass * 0.1
if (abs(previous_mass - region.mass)) >= previous_mass_thresh:
continue
else:
previous_mass = region.mass
f = FrameSample(
self.clip_id,
self.track_id,
Expand Down
2 changes: 1 addition & 1 deletion src/ml_tools/thermaldataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def main():
remapped_labels=get_remapped(),
excluded_labels=get_excluded(),
include_track=True,
num_frames=25,
num_frames=1,
)
print("Ecpoh size is", epoch_size)
# print(get_distribution(resampled_ds, len(labels), extra_meta=False))
Expand Down

0 comments on commit 8d12239

Please sign in to comment.