This file contains hidden or 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 torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class Net(nn.Module): | |
| def __init__(self): | |
| super(Net, self).__init__() | |
| # 1 input image channel, 6 output channels, 3x3 square convolution |
This file contains hidden or 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 torch | |
| import torch.nn as nn | |
| import torchvision | |
| import torchvision.transforms as transforms | |
| # Device configuration | |
| device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') | |
| # Hyper-parameters |
This file contains hidden or 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 matplotlib.pyplot as plt | |
| import matplotlib | |
| plt.figure(i, figsize=(5.5, 5)) | |
| plt.grid(True, linewidth=0.2) | |
| plt.plot(step, reward, linestyle=line_style[methods[i][ii]], linewidth=line_width[methods[i][ii]], color=colors[methods[i][ii]]) | |
| plt.ylim(top=y_top[i], bottom=y_bottom[i]) | |
| plt.xlim(left=0, right=10000) | |
| plt.rcParams.update({'font.size': 12}) |
This file contains hidden or 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
| isinstance(output_size, (int, tuple)) |
This file contains hidden or 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 | |
| np.random.randint(0, h - new_h) | |
| np.random.randn(in_size, out_size) |
This file contains hidden or 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
| class Rescale(object): | |
| """Rescale the image in a sample to a given size. | |
| Args: | |
| output_size (tuple or int): Desired output size. If tuple, output is | |
| matched to output_size. If int, smaller of image edges is matched | |
| to output_size keeping aspect ratio the same. | |
| """ | |
| def __init__(self, output_size): |
This file contains hidden or 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
| class FaceLandmarksDataset(Dataset): | |
| """Face Landmarks dataset.""" | |
| def __init__(self, csv_file, root_dir, transform=None): | |
| """ | |
| Args: | |
| csv_file (string): Path to the csv file with annotations. | |
| root_dir (string): Directory with all the images. | |
| transform (callable, optional): Optional transform to be applied | |
| on a sample. |
This file contains hidden or 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
| grid = utils.make_grid(images_batch) | |
| plt.imshow(grid.numpy().transpose((1, 2, 0))) |
This file contains hidden or 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
| dataloader = DataLoader(transformed_dataset, batch_size=4, | |
| shuffle=True, num_workers=4) |
This file contains hidden or 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 torch | |
| from torchvision import transforms, datasets | |
| data_transform = transforms.Compose([ | |
| transforms.RandomSizedCrop(224), | |
| transforms.RandomHorizontalFlip(), | |
| transforms.ToTensor(), | |
| transforms.Normalize(mean=[0.485, 0.456, 0.406], | |
| std=[0.229, 0.224, 0.225]) | |
| ]) |
OlderNewer