Skip to content

Instantly share code, notes, and snippets.

View gaiar's full-sized avatar

Gaiar Baimuratov gaiar

View GitHub Profile
def get_batch(self,bs=5):
bsize = bs if self.Q.qsize() > bs else self.Q.qsize()
if self.more() or not self.stopped:
frames = []
for i in range(bsize):
frames.append(self.Q.get())
return frames
return None
#!/bin/bash
HOST='<IP ADDRESS>'
USER='<USER>'
PASS='<PASSWORD>'
TARGETFOLDER='/media/external/record'
SOURCEFOLDER='/tmp/sd/record'
lftp -f "
set ftp:passive-mode on
set ftp:ssl-allow yes
@gaiar
gaiar / TF-TRT.py
Created January 29, 2020 11:08
TF-TRT 1.x Workflow With A SavedModel
import tensorflow as tf
from tensorflow.python.compiler.tensorrt import trt_convert as trt
BATCH_SIZE = 2
#GRAPH_PATH = '/home/gaiar/developer/megadetector/megadetector_v3_optimized.pb'
input_saved_model_dir = "/home/gaiar/developer/megadetector/megadetector/exported_model/saved_model"
output_saved_model_dir = "/home/gaiar/developer/megadetector/model_optimization/trt"
converter = trt.TrtGraphConverter(
input_saved_model_dir=input_saved_model_dir,
# import the necessary packages
from threading import Thread
import sys
import cv2
import time
from queue import Queue
class FileVideoStream:
def __init__(self, path, transform=None, resize=None, queue_size=128):
# Playing video from file
cap = cv2.VideoCapture('rackoon.mp4')
# Default resolutions of the frame are obtained.The default resolutions are system dependent.
# We convert the resolutions from float to integer.
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
# Define the codec and create VideoWriter object.The output is stored in 'output.avi' file.
out = cv2.VideoWriter(FILE_OUTPUT, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'),
@gaiar
gaiar / install_archiconda.sh
Last active May 13, 2019 15:13
Install ArchiConda on Samsung Note 9
#!/usr/bin/env bash
wget https://github.com/Archiconda/build-tools/releases/download/0.2.2/Archiconda3-0.2.2-Linux-aarch64.sh
chmod +x Archiconda3-0.2.2-Linux-aarch64.sh
./Archiconda3-0.2.2-Linux-aarch64.sh
@gaiar
gaiar / keras-training.log
Created May 11, 2019 11:53
Neural network training progress
Epoch 1/10
185/185 [==============================] - 266s 1s/step - loss: 0.2160 - acc: 0.9130 - val_loss: 0.7465 - val_acc: 0.6078
Epoch 00001: val_loss improved from inf to 0.74645, saving model to models/bird-vs-not-bird-weights-01.h5
Epoch 2/10
185/185 [==============================] - 258s 1s/step - loss: 0.1484 - acc: 0.9437 - val_loss: 0.6983 - val_acc: 0.6101
Epoch 00002: val_loss improved from 0.74645 to 0.69832, saving model to models/bird-vs-not-bird-weights-02.h5
Epoch 3/10
185/185 [==============================] - 258s 1s/step - loss: 0.1262 - acc: 0.9530 - val_loss: 0.6837 - val_acc: 0.6073
@gaiar
gaiar / split_dataset.py
Created May 3, 2019 11:15
Split dataset into Train and Validation parts
#Based on helper function from https://github.com/daanraman
import os
import shutil
import numpy as np
#Make sure all folders are present before running the script
ALL_DATA_HOME_DIR = "data"
DATA_TRAIN_DIR = "dataset/train"
DATA_TEST_DIR = "dataset/valid"
@gaiar
gaiar / remove_duplicates.py
Last active May 2, 2019 10:27
Removing duplicates from downloaded images
#!/usr/bin/env python
#Based on https://stackoverflow.com/questions/748675/finding-duplicate-files-and-removing-them
import sys
import os
import hashlib
import logging
logging.basicConfig(
filename='duplicates.log',
@gaiar
gaiar / rename_downloaded_files.py
Created May 2, 2019 10:17
Cleanup and rename downloaded images
import glob
import os
import shutil
import filetype
import logging
logging.basicConfig(
filename='renaming.log',
level=logging.DEBUG,
format='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s',