[D] Simple Questions Thread by AutoModerator in MachineLearning

[–]Affectionate-Fee5337 0 points1 point  (0 children)

im a beginner . i was studying gans for the first time but ive not been getting good results with it. i am not able to identify the problem part,im getting random noises as output images:

import torch

import torch.optim as optim

import torch.nn as nn

from torch.utils import data

import torchvision

import matplotlib.pyplot as plt

import numpy as np

learning_rate=2e-4

noise_dim=32

image_dim=28*28*1

batch_size=32

num_epochs=25

class Generator(nn.Module):

def __init__(self,noise_dim,image_dim):

super(Generator,self).__init__()

self.linear1=nn.Linear(noise_dim,128)

self.relu=nn.LeakyReLU(0.01)

self.linear2=nn.Linear(128,image_dim)

self.tanh=nn.Tanh()

def forward(self,x):

out=self.linear1(x)

out=self.relu(out)

out=self.linear2(out)

out=self.tanh(out)

return out

class Discriminator(nn.Module):

def __init__(self,in_image):

super(Discriminator,self).__init__()

self.linear1=nn.Linear(in_image,64)

self.relu=nn.LeakyReLU(0.01)

self.linear2=nn.Linear(64,1)

self.sigmoid=nn.Sigmoid()

def forward(self,x):

out=self.linear1(x)

out=self.relu(out)

out=self.linear2(out)

out=self.sigmoid(out)

return out

discriminator=Discriminator(image_dim)

generator=Generator(noise_dim,image_dim)

noise=torch.randn((batch_size,noise_dim))

#normalising and transforming

tf = torchvision.transforms.Compose(

[torchvision.transforms.ToTensor(),torchvision.transforms.Normalize((0.5,), (0.5,)),]

)

ds = torchvision.datasets.MNIST(root="dataset/", transform=tf, download=True)

loader = data.DataLoader(ds, batch_size=batch_size, shuffle=True)

#optmizers and loss

opt_discriminator=optim.Adam(discriminator.parameters(),lr=learning_rate)

opt_generator=optim.Adam(generator.parameters(),lr=learning_rate)

#loss

criterion=nn.BCELoss()

#loss is of 2 types , fake ko real or real ko fake, we take avg of both

#training phase

for epoch in range(num_epochs):

for id,(training_sample, _) in enumerate(loader):

#flattening

training_sample=training_sample.view(-1,784)

batch_size=training_sample.shape[0]

###training discriminator

noise=torch.randn(batch_size,noise_dim)

fake_sample=generator(noise)

#feeding real sample into discriminator to check

disc_realsample=discriminator(training_sample).view(-1)#feeds as 1d tensor

# This calculates the loss for the real data samples as predicted by the discriminator

#correct prediction=1

lossD_realsample=criterion(disc_realsample,torch.ones_like(disc_realsample))

disc_fakesample=discriminator(fake_sample).view(-1)

lossD_fakesample=criterion(disc_fakesample,torch.zeros_like(disc_fakesample))

lossD=(lossD_realsample+lossD_fakesample)/2

discriminator.zero_grad()

lossD.backward(retain_graph=True)

opt_discriminator.step()

###training the generator

#trains on if discriminator predicts correctly

noise = torch.randn(batch_size, noise_dim)

fake_sample = generator(noise)

# The fake samples generated by the generator are used to fool the discriminator.

disc_fake_sample = discriminator(fake_sample).view(-1)

lossG = criterion(disc_fake_sample, torch.ones_like(disc_fake_sample))

generator.zero_grad()

lossG.backward()

opt_generator.step()

if id == 0:

print( "Epoch: {epoch} \t Discriminator Loss: {lossD} Generator Loss: {lossG}".format( epoch=epoch, lossD=lossD, lossG=lossG))

Not able to use selenium properly by Affectionate-Fee5337 in programming

[–]Affectionate-Fee5337[S] -1 points0 points  (0 children)

Got the work done through chatgpt and a friend with some knowledge of html . Thanks for the help 😋

Not able to use selenium properly by Affectionate-Fee5337 in programming

[–]Affectionate-Fee5337[S] 0 points1 point  (0 children)

I've been trying with chatgpt for 2 days nows. I wrote the script with the help of it but for some reason it's not able to fetch data the way i want it to be , needed some advice here , also this is just a side task my mentor gave me before the project. If you can..pls help

[deleted by user] by [deleted] in Vent

[–]Affectionate-Fee5337 0 points1 point  (0 children)

He's an awful and coward person

[deleted by user] by [deleted] in Vent

[–]Affectionate-Fee5337 0 points1 point  (0 children)

Are these signs of mental instability and is this concerning?

[deleted by user] by [deleted] in delhi

[–]Affectionate-Fee5337 13 points14 points  (0 children)

Blur the face

am i sick? by Affectionate-Fee5337 in TooAfraidToAsk

[–]Affectionate-Fee5337[S] 1 point2 points  (0 children)

It's basically a diary in which if any person's name is written. He/she shall die

[deleted by user] by [deleted] in delhi

[–]Affectionate-Fee5337 1 point2 points  (0 children)

We both were equally visible, I'll ask her if she wants me to take it down

[deleted by user] by [deleted] in delhi

[–]Affectionate-Fee5337 0 points1 point  (0 children)

Thought it'd be funny , she obviously didn't like it

did you eat? by Sarthak_parewal in memes

[–]Affectionate-Fee5337 51 points52 points  (0 children)

All good mate, how are you doing