Skip to content

Instantly share code, notes, and snippets.

View bmabir17's full-sized avatar
🎯
Focusing

B M Abir bmabir17

🎯
Focusing
View GitHub Profile
@bmabir17
bmabir17 / DatasetTools.py
Last active July 19, 2021 14:20
Transfer Learning Models for Training Classifier
import numpy as np
from PIL import Image
from pathlib import Path
from collections import defaultdict
import keras
from tensorflow.keras.utils import Sequence
import logging
import matplotlib.pyplot as plt
import cv2
@bmabir17
bmabir17 / DatasetTools.py
Last active July 8, 2021 06:40
Logging Keras Validation Results with WandB
import numpy as np
from PIL import Image
from pathlib import Path
from collections import defaultdict
import keras
# import tensorflow as tf
# from tensorflow.python import keras
# from tensorflow.python.keras import backend as Keras
from tensorflow.keras.utils import Sequence
import logging
@bmabir17
bmabir17 / .bashrc
Last active May 13, 2021 11:28
Shorten bash path and add time, git_branch info with reference from https://superuser.com/a/1209333/1341976
git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
HOST='\[\033[02;36m\]\h'; HOST=' '$HOST
TIME='\[\033[01;31m\]\t \[\033[01;32m\]'
LOCATION=' \[\033[01;34m\]`pwd | sed "s#\(/[^/]\{1,\}/[^/]\{1,\}/[^/]\{1,\}/\).$'
BRANCH=' \[\033[00;33m\]$(git_branch)\[\033[00m\] '
PS1=$TIME$BRANCH$USER$HOST$LOCATION
# Default Optimization is choosen
converter.optimizations = [tf.lite.Optimize.DEFAULT]
# Convert to TFLite Model
tflite_model = converter.convert()
# Save Model as tflite format
tflite_path = "deeplabv3_mnv2_custom_257.tflite"
tflite_model_size = open(tflite_path, 'wb').write(tflite_model)
MODEL_FILE = "frozen_inference_graph_257.pb"
# Load the TensorFlow model
converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(
graph_def_file = MODEL_FILE,
input_arrays = ['sub_2'], # For the Xception model it needs to be `sub_7`, for MobileNet it would be `sub_2`
output_arrays = ['ResizeBilinear_2'],
input_shapes={'sub_2':[1,257,257,3]}
)
@bmabir17
bmabir17 / index.js
Created April 17, 2020 21:29
Firebase cloud function for firestore
const functions = require('firebase-functions');
const admin = require('firebase-admin');
// var serviceAccount = require("/home/bmabir/dev/tran-dao-8e837f43806d.json");
admin.initializeApp({
credential: admin.credential.applicationDefault()
});
const db = admin.firestore();
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
@bmabir17
bmabir17 / convert.py
Last active February 6, 2022 20:54
Converts the mask-rcnn keras model https://github.com/matterport/Mask_RCNN/releases/tag/v2.0 to tflite
import tensorflow as tf
import numpy as np
import mrcnn.model as modellib # https://github.com/matterport/Mask_RCNN/
from mrcnn.config import Config
import keras.backend as keras
PATH_TO_SAVE_FROZEN_PB ="./"
FROZEN_NAME ="saved_model.pb"
@bmabir17
bmabir17 / vae_model.py
Last active January 14, 2023 02:12
Resnet Variational autoencoder for image reconstruction
import torch
from torch import nn
import torch.nn.functional as F
import abc
import pytorch_ssim
import torchvision.models as models
from torch.autograd import Variable
class AbstractAutoEncoder(nn.Module):
from hikvisionapi import Client
import cv2
import numpy as np
cam = Client('http://192.168.1.2','admin','admin123',timeout=1)
cap=cv2.VideoCapture('rtsp://admin:[email protected]:554/main/av_stream')
#response = cam.System.deviceInfo(method='get')
#print(response)
#motion_detection_info = cam.System.Video.inputs.channels[1].motionDetection(method='get')