Skip to content

Instantly share code, notes, and snippets.

View SubhadityaMukherjee's full-sized avatar

Subhaditya Mukherjee SubhadityaMukherjee

View GitHub Profile
netD = Discriminator(ngpu).to(device)
if (device.type == 'cuda') and (ngpu > 1):
 netD = nn.DataParallel(netD, list(range(ngpu)))
netD.apply(weights_init)
print(netD)
criterion = nn.BCELoss()
fixed_noise = torch.randn(64, nz, 1, 1, device=device)
real_label = 1
fake_label = 0
optimizerD = optim.Adam(netD.parameters(), lr=lr, betas=(beta1, 0.999))
optimizerG = optim.Adam(netG.parameters(), lr=lr, betas=(beta1, 0.999))
img_list = []
G_losses = []
D_losses = []
iters = 0
for epoch in range(num_epochs):

    for i, data in enumerate(dataloader, 0):
    	# Part 1
        netD.zero_grad()
plt.figure(figsize=(10,5))
plt.title("Generator and Discriminator Loss During Training")
plt.plot(G_losses,label="G")
plt.plot(D_losses,label="D")
plt.xlabel("iterations")
plt.ylabel("Loss")
plt.legend()
plt.show()
#%%capture
fig = plt.figure(figsize=(8,8))
plt.axis("off")
ims = [[plt.imshow(np.transpose(i,(1,2,0)), animated=True)] for i in img_list]
ani = animation.ArtistAnimation(fig, ims, interval=1000, repeat_delay=1000, blit=True)
ani.save("anim.mp4")
HTML(ani.to_jshtml())
@SubhadityaMukherjee
SubhadityaMukherjee / links.md
Last active April 8, 2020 11:36
Important links
@SubhadityaMukherjee
SubhadityaMukherjee / read.md
Last active April 12, 2020 17:22
dataread
import pandas as pd
import numpy as np
import seaborn as sns

df = pd.read_csv("speed-dating-experiment/Speed Dating Data.csv", encoding="ISO-8859-1")
df.head(10) #shows the first 10 rows
df.shape # gives rows and columns
df2['match'].shape
pd.crosstab(index=df2["match"], columns="count")
to_remove = []
for a in df.columns:
if df[a].isna().sum() > 4000:
to_remove.append(a)
df = df.drop(to_remove, axis=1)
df.shape
col_0 count
match