Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
import time
total = len(data_df)
mean = []
sd=[]
program_starts = time.time()
for idx in range(total):
row = data_df.loc[idx]
img_id, img_label = row['Image'], row['Label']
img_fname = TRAIN_DIR + "/" + str(img_id) + ".png"
img = Image.open(img_fname)
imarr = np.array( img, dtype=np.float)
mean.append(np.mean( imarr, axis=(0, 1)))
sd.append(np.std( imarr, axis=(0, 1)))
print("Train set done within {} seconds".format((time.time() - program_starts)))
print("Number of train Images = ", len(mean))
print("[TrainSET] Mean = {}, STD= {}".format( np.mean(mean, axis=0), np.std(sd, axis=0) ))
test_df = pd.read_csv(TEST_CSV)
total = len(test_df)
for idx in range(total):
row = data_df.loc[idx]
img_id, img_label = row['Image'], row['Label']
img_fname = TEST_DIR + "/" + str(img_id) + ".png"
img = Image.open(img_fname)
imarr = np.array( img, dtype=np.float)
mean.append(np.mean( imarr, axis=(0, 1)))
sd.append(np.std( imarr, axis=(0, 1)))
print("Total set done within {} seconds".format((time.time() - program_starts)))
print("Number of Total Images = ", len(mean))
print("[Total] Mean = {}, STD= {}".format( np.mean(mean, axis=0), np.std(sd, axis=0) ))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-ba72e718a18d> in <module>
11 img_fname = TRAIN_DIR + "/" + str(img_id) + ".png"
12 img = Image.open(img_fname)
---> 13 imarr = np.array( img, dtype=np.float)
14 mean.append(np.mean( imarr, axis=(0, 1)))
15 sd.append(np.std( imarr, axis=(0, 1)))
TypeError: float() argument must be a string or a number, not 'PngImageFile'
Human Protein Multi Label Image Classification - Transfer Learning & Regularization
How a CNN learns (source):
Layer visualization (source):
Transfer learning (source):
This is a starter notebook for the competition Zero to GANs - Human Protein Classification. It incorporates transfer learning, and other techniques from https://jovian.ml/aakashns/05b-cifar10-resnet
import os
import torch
import pandas as pd
import numpy as np
from torch.utils.data import Dataset, random_split, DataLoader
from PIL import Image
import torchvision.models as models
import matplotlib.pyplot as plt
from tqdm.notebook import tqdm
import torchvision.transforms as T
from sklearn.metrics import f1_score
import torch.nn.functional as F
import torch.nn as nn
from torchvision.utils import make_grid
%matplotlib inline
Preparing the Data
DATA_DIR = '../input/jovian-pytorch-z2g/Human protein atlas'
TRAIN_DIR = DATA_DIR + '/train'
TEST_DIR = DATA_DIR + '/test'
TRAIN_CSV = DATA_DIR + '/train.csv'
TEST_CSV = '../input/jovian-pytorch-z2g/submission.csv'