Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import cv2
random_transform_args = {
'rotation_range': 10,
'zoom_range': 0.05,
'shift_range': 0.05,
'random_flip': 0.4,
}
@sizhky
sizhky / colab_important_snipplets.py
Created September 19, 2020 12:11 — forked from adityajn105/colab_important_snipplets.py
Google Colab important code snipplets
### Download a file to Local System from Colab
from google.colab import files
with open('example.txt', 'w') as f:
f.write('some content')
files.download('example.txt')
#======================================================================================================
#upload file to Colab from Local System
from google.colab import files
uploaded = files.upload()
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<title>Untitled1</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
def subplots(ims, nc=5, figsize=(5,5), **kwargs):
if len(ims) == 0: return
titles = kwargs.pop('titles',[None]*len(ims))
nr = (len(ims)//nc) if len(ims)%nc==0 else (1+len(ims)//nc)
logger.info(f'plotting {len(ims)} images in a grid of {nr}x{nc} @ {figsize}')
fig, axes = plt.subplots(nr,nc,figsize=figsize)
axes = axes.flat
for ix,(im,ax) in enumerate(zip(ims,axes)):
show(im, ax=ax, title=titles[ix], **kwargs)
blank = (np.eye(100) + np.eye(100)[::-1])
import cv2, os
def stem(fpath): return '.'.join(fname(fpath).split('.')[:-1])
def convert_mp4_to_frames(filename):
vidcap = cv2.VideoCapture(filename)
success,image = vidcap.read()
count = 0
while success:
os.makedirs(stem(filename), exist_ok=True)
cv2.imwrite(f"{stem(filename)}/{count}.jpg", image) # save frame as JPEG file
@sizhky
sizhky / mount.py
Created July 19, 2020 13:36
Mount a drive file in colab
!pip install PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
@sizhky
sizhky / youtube speed
Created July 4, 2020 15:19
Youtube speed over 9000
document.getElementsByTagName("video")[0].playbackRate = 9001
@sizhky
sizhky / set_background.py
Created June 14, 2020 09:30
set background in jupyter cells
from IPython.core.magic import register_cell_magic
from IPython.display import HTML, display
def set_background(color):
script = (
"var cell = this.closest('.jp-CodeCell');"
"var editor = cell.querySelector('.jp-Editor');"
"editor.style.background='{}';"
"this.parentNode.removeChild(this)"
).format(color)
import torch, math
import torch.nn as nn
import torch.nn.functional as F
class RetinaNet(nn.Module):
num_anchors = 9
def __init__(self, num_classes):
super(RetinaNet, self).__init__()
self.fpn = FPN50()
self.num_classes = num_classes
@sizhky
sizhky / jupyter theme.sh
Last active August 6, 2022 13:41
jupyter theme
jt -t grade3 -fs 95 -tfs 11 -nfs 115 -cellw 95% -T
jt -t onedork -fs 95 -tfs 11 -nfs 115 -cellw 88% -T -N