-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import sqlite3 | ||
import os | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
class DB: | ||
def __init__(self, sqlite_db_path): | ||
self.con = sqlite3.connect(sqlite_db_path) | ||
self.cur = self.con.cursor() | ||
|
||
self.cur.execute(''' | ||
CREATE TABLE IF NOT EXISTS Meta ( | ||
img_id TEXT PRIMARY KEY, | ||
start_mili INTEGER, | ||
end_mili INTEGER, | ||
num_masks INTEGER | ||
) | ||
''') | ||
self.cur.execute(''' | ||
CREATE TABLE IF NOT EXISTS ClassificationMeta ( | ||
img_id TEXT, | ||
pitcher_id TEXT, | ||
pred_species_1 TEXT, | ||
pred_species_1_conf REAL, | ||
pred_species_2 TEXT, | ||
pred_species_2_conf REAL, | ||
start_mili INTEGER, | ||
end_mili INTEGER, | ||
PRIMARY KEY (img_id, pitcher_id), | ||
FOREIGN KEY (img_id) REFERENCES Meta (img_id) | ||
) | ||
''') | ||
|
||
self.con.commit() | ||
|
||
def insert_into_meta(self, meta): | ||
insert_sql = ''' | ||
INSERT INTO Meta (img_id, start_mili, end_mili, num_masks) | ||
VALUES (?, ?, ?, ?) | ||
''' | ||
self.cur.execute(insert_sql, (meta.img_id, meta.start_mili, meta.end_mili, meta.num_masks)) | ||
self.con.commit() | ||
|
||
def insert_into_class_meta(self, img_id, classification_meta): | ||
insert_sql = ''' | ||
INSERT INTO ClassificationMeta (img_id, pitcher_id, pred_species_1, pred_species_1_conf, pred_species_2, pred_species_2_conf, start_mili, end_mili) | ||
VALUES (?, ?, ?, ?, ?, ?, ?, ?) | ||
''' | ||
self.cur.execute(insert_sql, ( | ||
img_id, | ||
classification_meta.pitcher_id, | ||
classification_meta.pred_species_1, | ||
classification_meta.pred_species_1_conf, | ||
classification_meta.pred_species_2, | ||
classification_meta.pred_species_2_conf, | ||
classification_meta.start_mili, | ||
classification_meta.end_mili, | ||
)) | ||
self.con.commit() | ||
|
||
db = DB(os.path.join(os.environ['DB_DIR'], 'inference.db')) | ||
|
||
def dump_meta(meta): | ||
db.insert_into_meta(meta) | ||
for class_meta in meta.classifications: | ||
db.insert_into_class_meta(meta.img_id, class_meta) | ||
logger.info(f"Dumped meta for {meta.img_id}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Meta: | ||
def __init__(self): | ||
self.img_id = None | ||
self.start_mili = None | ||
self.end_mili = None | ||
self.num_masks = None | ||
self.classifications = [] | ||
|
||
class ClassificationMeta: | ||
def __init__(self): | ||
self.pitcher_id = None | ||
self.pred_species_1 = None | ||
self.pred_species_1_conf = None | ||
self.pred_species_2 = None | ||
self.pred_sepcies_2_conf = None | ||
self.start_mili = None | ||
self.end_mili = None |