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
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from time import sleep | |
class Tweeter: | |
def login(self): | |
username = "your username/email will go here" | |
password = "and your password shall go here" | |
# opens up the browser window |
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
# everything here is a part of login function of Tweeter class | |
# Now we need to find the field where we want to type in the username/email | |
uname_field = driver.find_element_by_name("session[username_or_email]") | |
# typing the username | |
# Note: it's important to press tab using Keys.TAB after typing the username | |
# to switch to the password field (or we can add extra lines of code to click on it) | |
uname_field.send_keys(username, Keys.TAB) | |
# selecting the password field | |
pass_field = driver.find_element_by_name("session[password]") |
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
# This function is a part of Tweeter class which will allow us to tweet | |
def tweet(self): | |
tweet_text = input("Enter your tweet here: ") | |
driver = self.driver | |
sleep(3) | |
# finds the compose tweet button | |
tweet_btn = driver.find_element_by_xpath("//a[@aria-label=\"Tweet\"]") | |
tweet_btn.click() |
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
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from time import sleep | |
class Tweeter: | |
@classmethod | |
def login(self): | |
username = "your username/email will go here" | |
password = "and your password shall go here" | |
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
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import time | |
class Tweeter: | |
def __init__(self, username, password): | |
self.username = username | |
self.password = password | |
self.driver = webdriver.Chrome() # opens up the browser window |
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
classes = { | |
0: 'Angry', 1: 'Disgust', 2: 'Fear', 3: 'Happy', 4: 'Sad', 5: 'Surprise', 6: 'Neutral' | |
} |
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
# this is for the transforms | |
train_trfm = transforms.Compose( | |
[ | |
transforms.ToPILImage(), | |
transforms.Grayscale(num_output_channels=1), | |
transforms.RandomCrop(48, padding=4, padding_mode='reflect'), | |
transforms.RandomHorizontalFlip(), | |
transforms.ToTensor(), | |
transforms.Normalize((0.5), (0.5), inplace=True) | |
]) |
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
# Creating the class for our dataset for the FER | |
class FERDataset(Dataset): | |
def __init__(self, images, labels, transforms): | |
self.X = images | |
self.y = labels | |
self.transforms = transforms | |
def __len__(self): | |
return len(self.X) |
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
batch_num = 400 | |
train_dl = DataLoader(train_data, batch_num, shuffle=True, num_workers=4, pin_memory=True) | |
val_dl = DataLoader(val_data, batch_num*2, num_workers=4, pin_memory=True) |
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 |
OlderNewer