Skip to content

Instantly share code, notes, and snippets.

View satyajitghana's full-sized avatar
🐈
lost in code

Satyajit Ghana satyajitghana

🐈
lost in code
View GitHub Profile
import gradio as gr
import torch
import requests
from PIL import Image
from torchvision import transforms
model = torch.hub.load('pytorch/vision:v0.6.0',
'resnet18', pretrained=True).eval()
@satyajitghana
satyajitghana / create_svg_thumbnail.py
Created December 15, 2022 13:32
Creates a thumbnail in png given an svg image, needs `sudo apt install -y imagemagick librsvg2-bin`
import argparse
import subprocess
from pathlib import Path
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Just an example",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
{
"data": [
"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAAAChnVFJDAAABoAAAAChiVFJDAAABoAAAACh3dHB0AAAByAAAABRjcHJ0AAAB3AAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAFgAAAAcAHMAUgBHAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhZWiAAAAAAAABvogAAOPUAAAOQWFlaIAAAAAAAAGKZAAC3hQAAGNpYWVogAAAAAAAAJKAAAA+EAAC2z3BhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABYWVogAAAAAAAA9tYAAQAAAADTLW1sdWMAAAAAAAAAAQAAAAxlblVTAAAAIAAAABwARwBvAG8AZwBsAGUAIABJAG4AYwAuACAAMgAwADEANv/bAEMAAwICAwICAwMDAwQDAwQFCAUFBAQFCgcHBggMCgwMCwoLCw0OEhANDhEOCwsQFhARExQVFRUMDxcYFhQYEhQVFP/bAEMBAwQEBQQFCQUFCRQNCw0UFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFP/AABEIAQABAAMBIgACEQEDEQH/xAAdAAACA
@satyajitghana
satyajitghana / Scrape-Github-Repository-Issues-With-Comments-And-Reactions-GraphQL.ipynb
Last active August 2, 2021 17:08
Scrape-Github-Repository-Issues-With-Comments-And-Reactions-GraphQL.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@satyajitghana
satyajitghana / sst_dataset_augmentation.ipynb
Created June 6, 2021 07:15
SST_Dataset_Augmentation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@satyajitghana
satyajitghana / gitlab_ssh_protocol.md
Created May 3, 2021 19:16 — forked from mmngreco/gitlab_ssh_protocol.md
SSH git clone url format on gitlab

SSH git clone url format on gitlab

General syntax:

<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
                                    prefer the slash here ^

These URLs work:

@satyajitghana
satyajitghana / serverless.yml
Created January 3, 2021 13:25
serverless.yml with EFS attached
service: tejas-service
org: tensorclan
frameworkVersion: '2'
provider:
name: aws
runtime: python3.8
stage: dev
region: ap-south-1
import onnxruntime
ort_session = onnxruntime.InferenceSession("simple_pose_estimation.quantized.onnx")
def to_numpy(tensor):
return tensor.detach().cpu().numpy() if tensor.requires_grad else tensor.cpu().numpy()
# compute ONNX Runtime output prediction
ort_inputs = {ort_session.get_inputs()[0].name: to_numpy(tr_img.unsqueeze(0))}
ort_outs = ort_session.run(None, ort_inputs)
from onnxruntime.quantization import quantize
from onnxruntime.quantization import QuantizationMode
quantized_model = quantize(onnx_model, quantization_mode=QuantizationMode.IntegerOps, static=False)
onnx.save(quantized_model, 'simple_pose_estimation.quantized.onnx')
print_size_of_onnx_model(quantized_model)
import io
import numpy as np
import torch.onnx
# Input to the model
torch_model = new_model
batch_size = 1
x = torch.randn(batch_size, 3, 256, 256, requires_grad=True)
torch_out = torch_model(x)