Skip to content

Instantly share code, notes, and snippets.

View InputBlackBoxOutput's full-sized avatar
🐮

Rutuparn Pawar InputBlackBoxOutput

🐮
  • Boston, MA
View GitHub Profile
@InputBlackBoxOutput
InputBlackBoxOutput / check.py
Created March 12, 2023 17:27
Check TPU version on Google Colab
import os
from tensorflow.python.profiler import profiler_client
tpu_profile_service_address = os.environ['COLAB_TPU_ADDR'].replace('8470', '8466')
print(profiler_client.monitor(tpu_profile_service_address, 100, 2))
@InputBlackBoxOutput
InputBlackBoxOutput / scraper.py
Created February 26, 2023 19:49
Scrape images from a website
import os
import shutil
import requests
import time
import random
# pip install requests-html
from requests_html import HTMLSession
session = HTMLSession()
@InputBlackBoxOutput
InputBlackBoxOutput / clear.cpp
Created December 11, 2022 01:26
A workaroud to use clear as a command to clear Command Prompt
// A workaroud to use clear as a command to clear Command Prompt
// Step 1: g++ clear.cpp -o clear.exe
// Step 2: Add clear.exe directory to PATH enviroment variable
#include<cstdlib>
int main() {
system("cls");
return 0;
}
@InputBlackBoxOutput
InputBlackBoxOutput / serial.py
Created July 3, 2022 15:42
Print serial data sent over USB from a development board
import sys
import serial
import serial.tools.list_ports as port_list
def serial_communication():
ports = list(port_list.comports())
if ports == []:
print("No open ports found!")
sys.exit()
@InputBlackBoxOutput
InputBlackBoxOutput / convert.py
Created June 18, 2022 16:52
Convert bounding boxes from YOLO format into JSON format expected by edge-impulse-uploader
import os, glob, json
import cv2
class BoundingBoxConvertor:
def __init__(self):
self.label_map = {
"0":"class1",
"1":"class2",
"2":"class3"
}
@InputBlackBoxOutput
InputBlackBoxOutput / get_webpage.py
Created March 28, 2022 12:58
Get the HTML source code for a webpage
import requests
headers = {
'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
}
def get_webpage():
url = "www.google.com"
print(url)
response = requests.request("GET", url, headers=headers)
@InputBlackBoxOutput
InputBlackBoxOutput / segmentation.py
Created March 28, 2022 03:52
Green color segmentation using HSV value thresholding
import cv2
import numpy as np
import time
greenHSVLowerLimit = (24, 76, 0)
greenHSVUpperLimit = (84, 255, 255)
VideoStream = cv2.VideoCapture(0)
time.sleep(2.0)
@InputBlackBoxOutput
InputBlackBoxOutput / segmentation.py
Created March 28, 2022 03:44
Image segmentation using k-means clustering
import cv2
import numpy as np
import matplotlib.pyplot as plt
image = cv2.imread("sample-images/minions.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.imshow(image)
pixel_values = image.reshape((-1, 3))
pixel_values = np.float32(pixel_values)
@InputBlackBoxOutput
InputBlackBoxOutput / xml2yolo.py
Created March 23, 2022 10:12
labelImg: Convert annotations in XML to YOLO format
from xml.dom import minidom
import os
import glob
LUT = {"class0": 0, "class1": 1, "class2": 2}
def convert_coordinates(size, box):
dw = 1.0/size[0]
dh = 1.0/size[1]
x = (box[0]+box[1])/2.0
@InputBlackBoxOutput
InputBlackBoxOutput / json2yolo.py
Created March 23, 2022 10:09
labelImg: Convert annotations in JSON to YOLO format
import glob
import json
import cv2
LUT = {"class0": 0, "class1": 1, "class2": 2}
for each_file in glob.glob("data/*.json"):
with open(each_file) as json_file:
data = json.load(json_file)[0]