Skip to content

Instantly share code, notes, and snippets.

View boscacci's full-sized avatar
🎬
Object detecting

Robert Boscacci boscacci

🎬
Object detecting
View GitHub Profile
@boscacci
boscacci / inferences_to_coco_annotations.py
Last active August 9, 2022 20:22
Export icevision batch inferences as COCO (pseudo-label) annotations
from icevision.models.inference import *
import json
import numpy as np
[pred.add_component(FilepathRecordComponent()) for pred in preds]
[preds[_].set_filepath(img_files[_]) for _ in range(len(preds))]
for p in preds:
process_bbox_predictions(p,
PIL.Image.open(Path(p.pred.filepath)),
@boscacci
boscacci / two_sample_t-stat_welch.py
Last active December 1, 2023 17:32
Welch's Unequal Variances T-test
def twosample_tstat_welch(experimental, control):
"""
Runs Welch's unequal variances t-test
Accepts 2 pandas series or numpy arrays
Returns a t-stat
"""
xbar_1 = experimental.mean()
xbar_2 = control.mean()
var_1 = experimental.var()
var_2 = control.var()
@boscacci
boscacci / scene_heading_extractor.py
Last active August 17, 2021 16:04
Extract Scene Headings from Screenplay
import re
def extract_scene_headings(film_script_txtfile_path="scripts/no_country.txt", mode=1):
# A couple options on regex patterns, depending on script format. Might need tweaks per script
film_scene_heading_regexp_1 = "(?<=INT. |EXT. ).*(?=,)"
film_scene_heading_regexp_2 = "(?<=INT. |EXT. ).*(?= -)"
if mode == 1:
regexp = film_scene_heading_regexp_1
elif mode == 2:
@boscacci
boscacci / pd_csv2sql.py
Created November 8, 2019 22:57
Python Pandas - Write Very Large CSV file to (postgresql) SQL DB
import pandas as pd
from sqlalchemy import create_engine
# Your connection string format may vary by SQL flavor;
con = f'postgresql://{username}:{password}@{host}:5432/{database}'
eng = create_engine(con)
# Open csv file as stream and write to SQL, appending as you go:
for chunk in pd.read_csv('filename.csv', chunksize = 1000):
chunk.to_sql(name = 'giant_table',