- Collect user input and check if user's move is
rock
,paper
orscissors
and simultaneously userandom
library to generate a random computer move. - Use if-elif-else or if-else statements to compare the user's move and computer's move
- if user's move is superior to computer's move (eg:
rock
>scissors
and similarlypaper
>rock
), print that user won - else print user lost
- if user's move is superior to computer's move (eg:
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
JavaScript 27 mins █████████████████▎░░░ 82.3% | |
JSON 5 mins ███▋░░░░░░░░░░░░░░░░░ 17.8% |
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 | |
files = os.listdir() | |
for file in files: | |
if '_11zon' in file: | |
print(file) | |
os.rename(file, file.replace('_11zon', '')) |
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 typing | |
class ArticleField: | |
"""The `ArticleField` class for the Advanced Requirements.""" | |
def __init__(self, field_type: typing.Type[typing.Any]): | |
self.field_type = field_type | |
self.attribute = '' |
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
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') | |
while vid.isOpened(): | |
_, frame = vid.read() | |
# takes in a gray coloured filter of the frame | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
# initializing the haarcascade face detector | |
faces = face_cascade.detectMultiScale(frame) |
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
# function to turn photos to tensor | |
def img2tensor(x): | |
transform = transforms.Compose( | |
[transforms.ToPILImage(), | |
transforms.Grayscale(num_output_channels=1), | |
transforms.ToTensor(), | |
transforms.Normalize((0.5), (0.5))]) | |
return transform(x) | |
# the model for predicting |
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
torch.save(model.state_dict(), 'FER2013-Resnet9.pth') |
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
@torch.no_grad() # this is for stopping the model from keeping track of old parameters | |
def evaluate(model, val_loader): | |
# This function will evaluate the model and give back the val acc and loss | |
model.eval() | |
outputs = [model.validation_step(batch) for batch in val_loader] | |
return model.validation_epoch_end(outputs) | |
# getting the current learning rate | |
def get_lr(optimizer): | |
for param_group in optimizer.param_groups: |
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
def conv_block(in_chnl, out_chnl, pool=False, padding=1): | |
layers = [ | |
nn.Conv2d(in_chnl, out_chnl, kernel_size=3, padding=padding), | |
nn.BatchNorm2d(out_chnl), | |
nn.ReLU(inplace=True)] | |
if pool: layers.append(nn.MaxPool2d(2)) | |
return nn.Sequential(*layers) | |
class FERModel(FERBase): | |
def __init__(self, in_chnls, num_cls): |
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
def accuracy(outputs, labels): | |
_, preds = torch.max(outputs, dim=1) | |
return torch.tensor(torch.sum(preds==labels).item()/len(preds)) | |
class FERBase(nn.Module): | |
# this takes is batch from training dl | |
def training_step(self, batch): | |
images, labels = batch | |
out = self(images) # calls the training model and generates predictions |
NewerOlder