Skip to content

Instantly share code, notes, and snippets.

@previtus
previtus / show_prediction_label.py
Created July 25, 2019 15:03
Dataset handling in Change Detection Projects (arc gis tile exports and saved predictions)
filename = "vector_strip2_256x256_over32/vector_strip2_8790.TIF"
file1 = "Fold_0/"+filename
file2 = "Gts/"+filename
from skimage import io
import numpy as np
import matplotlib.pyplot as plt
# The prediction
@previtus
previtus / pretrain_encoder.py
Last active August 27, 2021 14:05
Siamese version of Segmentation networks provided by various backend encoders (with weights included) by https://github.com/qubvel/segmentation_models (update to have custom trained encoder).
# Train NN on some specific task (perhaps looking at some type of data)
# starts with ImageNet weights, but these are changed accordingly to what your task needs.
# later we can load these weights into the SiameseUnet model as a specific encoder (instead of using the Imagenet defaults).
import matplotlib, os, glob, fnmatch
if not('DISPLAY' in os.environ):
matplotlib.use("Agg") # when running over ssh on server
# FORCE CPU
#import os
mogrify -font Liberation-Sans -fill white -undercolor '#00000080' -pointsize 26 -gravity NorthEast -annotate +10+10 %t *.jpg
@previtus
previtus / darkflow_tester.py
Created December 19, 2018 11:21
simple_darkflow_tester
# [SETUP, get these:]
# built_graph/yolo.meta
# built_graph/yolo.pb
# (using # flow --model cfg/yolo.cfg --load bin/yolo.weights --savepb)
from darkflow.net.build import TFNet
import numpy
import os, fnmatch, random
import cv2
@previtus
previtus / model
Last active September 13, 2018 15:31
ML CLASS NOTES
from keras.models import Sequential
from keras.layers import Dense, Conv2D, MaxPooling2D, Flatten
model = Sequential()
model.add(Conv2D(32, (3,3), activation='relu', input_shape=input_shape))
model.add(Flatten())
model.add(Dense(10))
model.summary()
# link https://github.com/platanus/openface-api
(had this before)
(installed docker)
docker pull bamos/openface
git clone https://github.com/platanus/openface-api.git
cd openface-api
git init
git add --all
@previtus
previtus / load.py
Last active April 15, 2018 00:06
Load all JSONs and process one with selected keywords to txt files
import os, fnmatch, random
import json
from pprint import pprint
def load(path, keywords_find, keywords_exclude):
# Frames to crops
files = sorted(os.listdir(path))
#print("files",len(files), files[0:10])
files = fnmatch.filter(files, '*.json')
random.shuffle(files)
@previtus
previtus / foreground, background
Last active September 4, 2018 02:50
linux, ctrl+z, bg, fg - fun
ctrl + z = will suspend the currently foregrounded program
jobs = see suspended / running jobs with number
bg = will run in background (the most recently suspended program)
(use bg %2 with the job number, which you can check with jobs)
fg = will bring to foreground the most recently suspended program
# thanks to https://github.com/bapoczos/ArtML/blob/master/fast-style-transfer/transform_video.py
# thanks to Barnabas Poczos and Gene Kogan
import subprocess, shutil
import os, fnmatch
in_args = [
'ffmpeg',
'-i', in_path,
'%s/frame_%%d.png' % in_dir
#when facing similar issue to the one mentioned at https://github.com/tensorflow/tensorflow/issues/1439
import tensorflow as tf
print("Count of global variables", len(tf.global_variables()))
print("Count of graph elements",len(tf.get_default_graph().get_operations()))