Hi there, when i was training the neural network the system shows this below is my code
depth=[4,8]
class ConvNet(nn.Module):
def init(self):
super(ConvNet,self).init()
self.conv1=nn.Conv2d(1,4,5,padding=2)
self.pool=nn.MaxPool2d(2,2)
#No2.Convolution
self.conv2=nn.Conv2d(depth[0],depth[1],5,padding=2)
self.fc1=nn.Linear(image_size//4image_size//4depth[1],512)#int division
self.fc2=nn.Linear(512,num_classes)
def forward(self,x):
x=self.conv1(x)
x=F.relu(x)
x=self.pool(x)
x=self.conv2(x)
x=F.relu(x)
x=self.pool(x)
x=x.view(-1,image_size//4image_size//4depth[1])
x=F.relu(self.fc1(x))
x=F.dropout(x,training=self.training)
x=self.fc2(x)
x=F.log_softmax(x,dim=1)
return x
def retreive_features(self,x):#get_features maps
features_map1=F.relu(self.conv1(x))
x=self.pool(feature_map1)
features_map2=F.relu(self.conv2(x))
return (features_map1,features_map2)
criterion=nn.CrossEntropyLoss()
optimizer=optim.SGD(net.parameters(),lr=0.001,momentum=0.9)
record=[]
weights=[]
for epoch in range(num_epochs):
#train_rights=[]
for batch_idx,(data,target) in enumerate(train_loader):
data,target=Variable(data).cuda(),Variable(target).cuda()#change Tensor to Variable
net.train()
output=net(data)
loss=criterion(output,target)#calculate loss
optimizer.zero_grad()
loss.backward()
optimizer.step()
if batch_idx%100==0:
net.eval()
#val_rights=[]
print(loss)
for (data,target) in validation_loader:
data,target=Variable(data).cuda(),Variable(target).cuda()
output=net(data)
My TEMP MEMEORY is 16GB it rises from 4.8 to 7.3 then it shows the message->kernel have died
it will restart automatically ,how can i do?
PS:my init has underline so don’t worry