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 matplotlib.pyplot as plt | |
# image modules | |
from PIL import Image | |
import matplotlib.image as mpimg | |
import cv2 | |
# PyTorch | |
import torch | |
from torch.utils import data | |
from torchvision import transforms |
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 matplotlib.pyplot as plt | |
# Input x, output y | |
x = np.linspace(0, 2*np.pi, 400) | |
y = np.sin(x**2) | |
# Creates figure first | |
my_dpi = 200 | |
fig = plt.figure(figsize=(4, 2), dpi=my_dpi) |
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 matplotlib.pyplot as plt | |
# Input x, output y | |
x = np.linspace(0, 2*np.pi, 400) | |
y = np.sin(x**2) | |
# Creates figure first | |
my_dpi = 40 | |
fig = plt.figure(figsize=(20, 10), dpi=my_dpi) |
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 matplotlib.pyplot as plt | |
# Input x, output y | |
x = np.linspace(0, 2*np.pi, 400) | |
y = np.sin(x**2) | |
# make multiple subplots. | |
# you can define the size of figure and dpi (dot per inch, defalt dpi=72) | |
my_dpi = 50 |
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 matplotlib.pyplot as plt | |
# Input x, output y | |
x = np.linspace(0, 2*np.pi, 400) | |
y = np.sin(x**2) | |
# Creates fig and ax from subplots(). | |
# But only create a single plot | |
fig, ax = plt.subplots() |
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 matplotlib.pyplot as plt | |
# Input x, output y | |
x = np.linspace(0, 2*np.pi, 400) | |
y = np.sin(x**2) | |
# Plot | |
plt.plot(x, y) | |
# Change the fontsize of ticks | |
plt.xticks(fontsize=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
# data loader | |
batch_size = 1 | |
num_workers = 4 | |
data_loader = torch.utils.data.DataLoader(my_dataset, | |
batch_size=batch_size, | |
shuffle=False, | |
num_workers=num_workers | |
) |
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
# data directory | |
root = "my_data" | |
# assume we have 3 jpg images | |
filenames = ['img1.jpg', 'img2.jpg', 'img3.jpg'] | |
# the class of image might be ['black cat', 'tabby cat', 'tabby cat'] | |
labels = [0, 1, 1] | |
# create own Dataset |
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 | |
import torch | |
from torch.utils import data | |
from PIL import Image | |
from torchvision import transforms | |
class simpleDataset(data.Dataset): | |
# initialise function of class | |
def __init__(self, root, filenames, labels): |
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 torchvision.models.detection.faster_rcnn import FastRCNNPredictor | |
def get_model_instance_segmentation(num_classes): | |
# load an instance segmentation model pre-trained pre-trained on COCO | |
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=False) | |
# get number of input features for the classifier | |
in_features = model.roi_heads.box_predictor.cls_score.in_features | |
# replace the pre-trained head with a new one | |
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes) |
NewerOlder