Skip to content

Commit

Permalink
upload random on init
Browse files Browse the repository at this point in the history
  • Loading branch information
bw4sz committed Nov 26, 2024
1 parent e1ba9a9 commit 063044a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,16 @@ def preprocess_and_train(config, validation_df=None, model_type="detection"):
root_dir=config.detection_model.train_image_dir,
save_dir=config.detection_model.crop_image_dir)

validation_df = data_processing.preprocess_images(validation_df,
if not validation_df.empty:
validation_df = data_processing.preprocess_images(validation_df,
root_dir=config.detection_model.train_image_dir,
save_dir=config.detection_model.crop_image_dir)

# Limit empty frames
if config.detection_model.limit_empty_frac > 0:
train_df = limit_empty_frames(train_df, config.detection_model.limit_empty_frac)
validation_df = limit_empty_frames(validation_df, config.detection_model.limit_empty_frac)
if not validation_df.empty:
validation_df = limit_empty_frames(validation_df, config.detection_model.limit_empty_frac)

# Train model
# Load existing model
Expand Down
15 changes: 15 additions & 0 deletions src/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime
import os
import glob
import random

import pandas as pd
from omegaconf import DictConfig
Expand Down Expand Up @@ -37,6 +39,19 @@ def run(self):
**self.config.label_studio)
if new_annotations is None:
print("No new annotations, exiting")
if self.config.force_upload:
image_paths = glob.glob(os.path.join(self.config.active_learning.image_dir, "*.jpg"))
image_paths = random.sample(image_paths, 10)
label_studio.upload_to_label_studio(images=image_paths,
sftp_client=self.sftp_client,
label_studio_project=self.label_studio_project,
images_to_annotate_dir=self.config.active_learning.image_dir,
folder_name=self.config.label_studio.folder_name,
preannotations=None
)
return None
# Select images to upload

return None

# Given new annotations, propogate labels to nearby images
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ def config(tmpdir_factory):

# Reporting
cfg.reporting.image_dir = cfg.detection_model.train_image_dir

cfg.reporting.report_dir = tmpdir_factory.mktemp("reports").strpath

return cfg
10 changes: 10 additions & 0 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ def test_pipeline_run(config, label_studio_client):
"""Test complete pipeline run"""
pipeline = Pipeline(cfg=config)
pipeline.run()


@pytest.mark.integration
def test_first_phase(config, label_studio_client):
"""Test init phase with no data"""
# Set validation csv paths to None
config.detection_model.validation_csv_path = None
config.classification_model.validation_csv_path = None
pipeline = Pipeline(cfg=config)
pipeline.run()

0 comments on commit 063044a

Please sign in to comment.