Skip to content

Instantly share code, notes, and snippets.

@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)
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
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])
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>
@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()
import numpy as np
import cv2
random_transform_args = {
'rotation_range': 10,
'zoom_range': 0.05,
'shift_range': 0.05,
'random_flip': 0.4,
}
import requests
import getpass
import sys
LOGIN_URL = "http://zeus.robots.ox.ac.uk/vgg_face2/login/"
FILE_URL = "http://zeus.robots.ox.ac.uk/vgg_face2/get_file?fname=vggface2_test.tar.gz"
print('Please enter your VGG Face 2 credentials:')
user_string = input(' User: ')
password_string = getpass.getpass(prompt=' Password: ')
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/Untitled.ipynb (unless otherwise specified).
__all__ = ['iou', 'patch', 'multi_patch']
# Cell
#export
from torch_snippets import *
def iou(A,B):
A = np.array(A)
B = np.array(B)
@sizhky
sizhky / eng.testa
Created January 24, 2021 08:24
CoNLL2003 NER Tagging Datasets
CRICKET O
- O
LEICESTERSHIRE I-ORG
TAKE O
OVER O
AT O
TOP O
AFTER O
INNINGS O
VICTORY O
@sizhky
sizhky / remove_jupyter_notebook_cells_output.py
Last active January 5, 2023 14:18 — forked from damianavila/remove_output.py
Remove output from Jupyter notebook from the command line (dev version 1.0)
import sys
import io
import os
from IPython.nbformat.current import read, write
def remove_outputs(nb):
"""remove the outputs from a notebook"""
for ws in nb.worksheets:
for cell in ws.cells:
if cell.cell_type == 'code':