Skip to content

Instantly share code, notes, and snippets.

@tarun-ssharma
tarun-ssharma / create_python3_venv.md
Created January 17, 2022 03:38
[MacOS] Create virtual environment for python3 libraries

Steps:

  1. Install python3 (follow https://docs.python-guide.org/starting/install3/osx/)
  2. Install virtualenv pip3 install virtualenv
  3. Make a virtual environment within current directory virtualenv -p python3 ./venv
  4. Activate the virtual environment for working with it source ./venv/bin/activate
  5. Deactivate it when done (Why? So you can work with other virtual environments or the global environment) deactivate
@tarun-ssharma
tarun-ssharma / calculate_mean_ap.py
Created February 21, 2022 15:42 — forked from sadjadasghari/calculate_mean_ap.py
Calculate mean Average Precision (mAP) for a set of ground truth and predicted bounding boxes for a set of images.
"""
author: Timothy C. Arlen
date: 28 Feb 2018
revised by: Sadjad Asghari Esfeden
date: 10 Sep 2018
Calculate Mean Average Precision (mAP) for a set of bounding boxes corresponding to specific
image Ids. Usage:
@tarun-ssharma
tarun-ssharma / Enabling case-insensitive auto-complete for terminal in MacOS BigSur.md
Last active July 28, 2024 11:10
Enable case-insensitive auto-complete whilst giving preference to actual matches

Add these two lines to your ~/.zshrc file:

zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
autoload -Uz compinit && compinit

Tested on:

MacOS BigSur Version 11.5.1
@tarun-ssharma
tarun-ssharma / quantized-inference-example.py
Created March 8, 2022 12:21 — forked from ShawnHymel/quantized-inference-example.py
TensorFlow Lite (TFLite) Python Inference Example with Quantization
# TFLite quantized inference example
#
# Based on:
# https://www.tensorflow.org/lite/performance/post_training_integer_quant
# https://www.tensorflow.org/lite/api_docs/java/org/tensorflow/lite/Tensor.QuantizationParams
import numpy as np
import tensorflow as tf
# Location of tflite model file (float32 or int8 quantized)
@tarun-ssharma
tarun-ssharma / yolov4.py
Created March 8, 2022 12:21 — forked from YashasSamaga/yolov4.py
YOLOv4 on OpenCV DNN
import cv2
import time
CONFIDENCE_THRESHOLD = 0.2
NMS_THRESHOLD = 0.4
COLORS = [(0, 255, 255), (255, 255, 0), (0, 255, 0), (255, 0, 0)]
class_names = []
with open("classes.txt", "r") as f:
class_names = [cname.strip() for cname in f.readlines()]
@tarun-ssharma
tarun-ssharma / detection_PC.py
Created April 22, 2022 02:40 — forked from iwatake2222/detection_PC.py
Object detection using MobileNet SSD with tensorflow lite (with and without Edge TPU)
# -*- coding: utf-8 -*-
import cv2
import tensorflow as tf
import numpy as np
# https://www.tensorflow.org/lite/guide/hosted_models
# http://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip
def detect_from_camera():
@tarun-ssharma
tarun-ssharma / convert_tflite_rep_data_int8.md
Last active April 22, 2022 02:44 — forked from dansitu/convert.py
Convert to tflite with randomly picked representative dataset
model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
@tarun-ssharma
tarun-ssharma / ubuntu1804cuda10.sh
Created May 9, 2022 06:19 — forked from fo40225/ubuntu1804cuda10.sh
install cuda 10 on ubuntu 18.04
# echo "blacklist nouveau" | sudo tee -a /etc/modprobe.d/blacklist-nouveau.conf > /dev/null
# echo "options nouveau modeset=0" | sudo tee -a /etc/modprobe.d/blacklist-nouveau.conf > /dev/null
# sudo update-initramfs -u
sudo apt update
sudo apt -y install build-essential
sudo apt update
sudo apt -y install linux-headers-$(uname -r)
import matplotlib
import matplotlib.pyplot as plt

import os
import random
import io
import imageio
import glob
import scipy.misc
from object_detection.utils import config_util
from object_detection.builders import model_builder
#Where to save the SavedModel
output_directory = './try2_trained_model'
#Recover our saved model with the latest checkpoint:
pipeline_config = 'pipeline.config'
#Put the last ckpt from training in here, don't use long pathnames:
model_dir = './trained_checkpoints/ckpt-31'