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
# Looping Over Collection Forward | |
colors = ["red", "green", "blue"] | |
# bad | |
for i in range(len(colors)): | |
print(colors[i]) | |
# good | |
for color in colors: | |
print(color) |
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
# Looping Over Collection with Indice Forward | |
colors = ["red", "green", "blue"] | |
# bad | |
for i in range(len(colors)): | |
print(i,'--',colors[i]) | |
# good | |
for i, color in enumerate(colors): | |
print(i, '--', color) |
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
# Looping Over Two Collection | |
names = ["raymond", "rachel","matthew"] | |
colors = ["red", "green", "blue"] | |
# bad | |
n = min(len(names), len(colors)) | |
for i in range(n): | |
print(names[i], '--', colors[i]) | |
# good |
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
# Looping Over Collection Backward | |
colors = ["red", "green", "blue"] | |
# bad | |
for i in range(len(colors)-1, -1, -1): | |
print(colors[i]) | |
# good | |
for color in reversed(colors): | |
print(color) |
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
import sys | |
#################### | |
### Set the hyperparameters in you myanswers.py file ### | |
#################### | |
from my_answers import iterations, learning_rate, hidden_nodes, output_nodes | |
N_i = train_features.shape[1] | |
network = NeuralNetwork(N_i, hidden_nodes, output_nodes, learning_rate) |
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
import numpy as np | |
class NeuralNetwork(object): | |
def __init__(self, input_nodes, hidden_nodes, output_nodes, learning_rate): | |
# Set number of nodes in input, hidden and output layers. | |
self.input_nodes = input_nodes | |
self.hidden_nodes = hidden_nodes | |
self.output_nodes = output_nodes |
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
import random | |
import torch | |
import pathlib | |
import os | |
from torch.utils import data | |
import PIL | |
import PIL.Image | |
class SiameseDataset(data.Dataset): | |
def __init__(self, root, ext, transform=None, pair_transform=None, target_transform=None): |
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
import numpy as np | |
import cv2 | |
x1, x2 = 100,400 | |
y1, y2 = 10, 310 | |
cap = cv2.VideoCapture(0) | |
while(True): | |
ret, frame = cap.read() | |
r = cv2.rectangle(frame,(y1,x2),(y2,x1),(0,255,0),3) | |
crop = frame[x1:x2, y1:y2] |
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
import numpy as np | |
import cv2 | |
def center_rectangle(frame): | |
h,w,d = frame.shape | |
x1,y1 = h//4, w//4 | |
x2,y2 = h-x1, w-y1 | |
rr = cv2.rectangle(frame,(y1,x1),(y2,x2),(0,255,0),3) | |
crop = frame[x1:x2, y1:y2] | |
return rr |
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
import os | |
base_path = '/home/nunenuh/Desktop/skripsi/dataset/testing' | |
def rescale(base_path,percent): | |
dirz = os.listdir(base_path) | |
my_list = [] | |
for dr in dirz: | |
path = os.path.join(base_path, dr,'*.jpg') | |
my_list.append(path) |