Skip to content

Instantly share code, notes, and snippets.

View Borda's full-sized avatar

Jirka Borovec Borda

View GitHub Profile
@Borda
Borda / ci-update-submodules.yml
Last active October 30, 2023 15:12
Automated git-submodule updates via PR
name: Update git submodules
on:
pull_request:
branches: ["main"]
paths:
- ".github/workflows/ci-update-submodules.yml"
schedule:
# on Sundays
- cron: "0 0 * * 0"
@Borda
Borda / failing-build.yml
Last active September 20, 2023 09:08
blog_retry-failed-checks
name: Sample build
on:
- push
- pull_request
- workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest
steps:
@Borda
Borda / blog_predict-plant.py
Created September 13, 2021 12:04
Simple Submitting Kernel to Kaggle Competition
preds = []
# move model to GPU for faster inference and set evaluation
model.cuda().eval()
for imgs, names in dm.test_dataloader():
# for the prediction we do not need gradients
with torch.no_grad():
onehots = model(imgs.cuda()).cpu()
# aggregate particular preditions
for oh, name in zip(onehots, names):
lbs = dm.onehot_to_labels(oh)
@Borda
Borda / blog_run-plant-from-package.py
Created September 4, 2021 19:18
Converting Kaggle Training Notebooks to Shareable Code
from pytorch_lightning import Trainer
from kaggle_plantpatho.data import PlantPathologyDM
from kaggle_plantpatho.models import LitResnet, MultiPlantPathology
# create DataModule with training/validation split
dm = PlantPathologyDM(batch_size=98)
# initialize ResNet50 network
net = LitResnet(arch='resnet50', num_classes=dm.num_classes)
# initialize PL module with ResNet50
model = MultiPlantPathology(model=net, lr=6e-4)
fig = plt.figure(figsize=(3, 7))
for imgs, lbs in dm.val_dataloader():
# some stats about the batch - label distribution
print(f'batch labels: {torch.sum(lbs, axis=0)}')
print(f'image size: {imgs[0].shape}')
# similar as above show just first images from the batch
for i in range(3):
ax = fig.add_subplot(3, 1, i + 1, xticks=[], yticks=[])
ax.imshow(np.rollaxis(imgs[i].numpy(), 0, 3))
ax.set_title(lbs[i])
@Borda
Borda / blog_mproc-img-scale.py
Created August 19, 2021 13:33
blog: scale images with multiprocessing
import os, tqdm, glob
import multiprocessing as mproc
ls_images = glob.glob("plant-pathology/train_images/*.jpg")
print(f'found images: {len(ls_images)}')
def _convert(pimg: str):
# it can be replaced by opencv implementation...
os.system(f'convert -resize 640 point {pimg} {pimg}')
@Borda
Borda / blog_show-COVID-detection.py
Last active August 19, 2021 13:36
blog: show COVID detection bbox
import pydicom
from pydicom.pixel_data_handlers import apply_voi_lut
# load the DICOM file
dicom = pydicom.dcmread(dicom_path)
# extract the image bitmap
img = apply_voi_lut(dicom.pixel_array, dicom)
import matplotlib.pyplot as plt
@Borda
Borda / repo_simple_stats.py
Last active November 2, 2020 23:53
Make a simple repository statistic about user contributions.
"""
Make a simple repository statistic about user contributions.
## Resources
- https://developer.github.com/v3/pulls/
- http://zetcode.com/python/requests/
- https://developer.github.com/v3/#authentication
**Requirements:**
```
@Borda
Borda / changelog_parser_PR_authors.py
Last active December 20, 2021 16:36
use Fire CLI
"""
Parse all users from release notes according to PR reference.
Resources:
- https://developer.github.com/v3/pulls/
- http://zetcode.com/python/requests/
- https://developer.github.com/v3/#authentication
"""
import json
@Borda
Borda / jirkify.py
Last active January 9, 2019 10:26
jirkify
import string
import random
__version__ = '0.1.1j'
DEFAULT = 0.5
def jirkify(message, jirkaness=DEFAULT):
""" traslation to spoken/written form