-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,67 @@ | ||
import superimport | ||
# import superimport | ||
|
||
import os | ||
import cv2 # open CV 2 | ||
import cv2 # open CV 2 | ||
|
||
def compute_image_resize(image, width = None, height = None): | ||
|
||
def compute_image_resize(image, width=None, height=None): | ||
# From https://stackoverflow.com/questions/44650888/resize-an-image-without-distortion-opencv | ||
# initialize the dimensions of the image to be resized and | ||
# grab the image size | ||
dim = None | ||
(h, w) = image.shape[:2] | ||
|
||
# check to see if the width is None | ||
if width is None: | ||
# calculate the ratio of the height and construct the | ||
# dimensions | ||
r = height / float(h) | ||
dim = (int(w * r), height) | ||
|
||
# otherwise, the height is None | ||
else: | ||
# calculate the ratio of the width and construct the | ||
# dimensions | ||
r = width / float(w) | ||
dim = (width, int(h * r)) | ||
|
||
return dim | ||
def image_resize(img_path,size=None,ratio=None): | ||
|
||
|
||
def image_resize(img_path, size=None, ratio=None): | ||
if not size: | ||
size=[0,480] | ||
size = [0, 480] | ||
img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED) | ||
dim = compute_image_resize(img, height=size[1]) | ||
img = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) | ||
img = cv2.resize(img, dim, interpolation=cv2.INTER_AREA) | ||
return img | ||
|
||
|
||
def git_ssh(git_command, email, username, verbose=False): | ||
'''Execute a git command via ssh from colab. | ||
Details in https://github.com/probml/pyprobml/blob/master/book1/intro/colab_intro.ipynb | ||
"""Execute a git command via ssh from colab. | ||
Details in | ||
https://github.com/probml/pyprobml/blob/master/notebooks/tutorials/colab_intro.ipynb | ||
Authors: Mahmoud Soliman <[email protected]> and Kevin Murphy <[email protected]> | ||
''' | ||
git_command=git_command.replace(r"https://github.com/","[email protected]:") | ||
print('executing command via ssh:', git_command) | ||
""" | ||
git_command = git_command.replace(r"https://github.com/", "[email protected]:") | ||
print("executing command via ssh:", git_command) | ||
# copy keys from drive to local .ssh folder | ||
if verbose: | ||
print('Copying keys from gdrive to local VM') | ||
os.system('rm -rf ~/.ssh') | ||
os.system('mkdir ~/.ssh') | ||
os.system('cp -r /content/drive/MyDrive/ssh/* ~/.ssh/') | ||
os.system('ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts') | ||
os.system('ssh -T [email protected]') # test | ||
print("Copying keys from gdrive to local VM") | ||
os.system("rm -rf ~/.ssh") | ||
os.system("mkdir ~/.ssh") | ||
os.system("cp -r /content/drive/MyDrive/ssh/* ~/.ssh/") | ||
os.system("ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts") | ||
os.system("ssh -T [email protected]") # test | ||
# git commands | ||
if verbose: | ||
print('Executing git commands') | ||
os.system('git config --global user.email {}'.format(email)) | ||
os.system('git config --global user.name {}'.format(username)) | ||
print("Executing git commands") | ||
os.system("git config --global user.email {}".format(email)) | ||
os.system("git config --global user.name {}".format(username)) | ||
os.system(git_command) | ||
# cleanup | ||
if verbose: | ||
print('Cleanup local VM') | ||
os.system('rm -r ~/.ssh/') | ||
print("Cleanup local VM") | ||
os.system("rm -r ~/.ssh/") | ||
os.system('git config --global user.email ""') | ||
os.system('git config --global user.name ""') | ||
os.system('git config --global user.name ""') |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters