I am trying to solve the supervsied learning problem (housing price) using pytorch and I encounter CUDA error?

M

Manish Kumar Singh

Guest
Manish Kumar Singh Asks: I am trying to solve the supervsied learning problem (housing price) using pytorch and I encounter CUDA error?
I am getting the following error:

Code:
    ---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_17/1714279870.py in <module>
      4 
      5 
----> 6 data_tensor = CustomData(data)
      7 model = NeuralNetwork().to(device)
      8 train_data_tensor = DataLoader(data_tensor,batch_size,shuffle=True)

/tmp/ipykernel_17/3667328859.py in __init__(self, data, transform, target_transform)
     33         #self.data = data
     34         self.label = data[:,-1]
---> 35         self.label = self.label.to(device)
     36 
     37         self.feature = data[:,:-1]

RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

My code is

Code:
import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
from pandas import DataFrame
from torch.utils.data import Dataset
import torch

import torch.nn as nn
from torch.utils.data import DataLoader
import torchvision
from torchvision import datasets, transforms
import torch.optim as optim
from torch.autograd import Variable
import torch.nn.functional as F
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

Here I try fill gaps in the data and also convert text data (like good, and bad) into numbers and finally convert the entire thing into a tensor. So far no error.

Code:
data = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv')
data_cat = data[[str(i) for i in data.columns if data[str(i)].dtype == object]]
data_cat = data_cat.rank(axis=0, method='dense', na_option='top', ascending=False).astype(float)#converting text data to numbers
data_cat.fillna(0)
data_num = data[[str(i) for i in data.columns if data[str(i)].dtype != object]]
data_val = data_num.iloc[:,-1]
data_val = data_val.fillna(0)
data_num = data_num.iloc[:,:-1]
data_num = (data_num - data_num.mean())/(data_num.std())
data_num = data_num.fillna(0)
data = pd.concat([data_cat,data_num,data_val],axis=1)
data = torch.from_numpy(data.to_numpy())

Now I create a dataset to be used in NeuralNetwork via Dataloader. Again so far so good.

Code:
class CustomDataset(Dataset):
    def __init__(self,feature, label, transform=None, target_transform=None):
        self.feature = feature
        self.label = label
        self.transform = transform
        self.target_transform = target_transform
    def __len__(self):
        return len(self.label)
    def __getitem__(self, idx):
        feature = self.feature[idx]
        label = self.label[idx]
        if self.transform:
            feature = self.transform(feature)
        if self.target_transform:
            label = self.target_transform(label)
        return feature, label      
data_tensor = CustomDataset(data[:,:-1],data[:,-1])

Since I will be using GPU, I define the device.

Code:
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using {device} device")

This is my nn model. Because there are categorical data, I am using an embedding layer first.

Code:
class NeuralNetwork(nn.Module):
    def __init__(self):
        super(NeuralNetwork, self).__init__()
        
        self.linear_relu_stack = nn.Sequential(
            nn.Embedding(79,10),
            nn.Linear(70, 10),
            nn.ReLU(),
            nn.Linear(10, 10),
            nn.ReLU(),
            nn.Linear(10, 10),
            nn.ReLU(),            
            nn.Linear(10, 1),
        )
    def forward(self, x):
        logits = self.linear_relu_stack(x)
        return logits

These are my hyperprameters.

Code:
learning_rate = 0.005
batch_size = 20
num_of_epoch = 50

Now I am setting up the training process. I suspect this is where the bug lies.

Code:
model = NeuralNetwork().to(device)
train_data_tensor = DataLoader(data_tensor,batch_size,shuffle=True)
loss_fn = nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
def train_loop(data_loader, model, loss_fn, optimizer):
    size = len(data_loader.dataset)
    for batch, (X, y) in enumerate(data_loader):
        # Compute prediction and loss
        pred = model(X)
        loss = loss_fn(pred, y)
        # Backpropagation
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()        
        if batch % 100 == 0:
            loss, current = loss.item(), batch * len(X)
            print(f"loss: {loss:>7f}  [{current:>5d}/{size:>5d}]")

#Actual training
for t in range(num_of_epoch):
    print(f"Epoch {t+1}\n-------------------------------")
    train_loop(train_data_tensor, model, loss_fn, optimizer)
    
print("Done")

Can someone help me rectify errors in code?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.
 

Unreplied Threads

Data science journals that focus on industrial applications?

Student Asks: Data science journals that focus on industrial applications?
Academic conferences are known for the go-to when looking up up-to-date development in the field of data science. However, I find that most papers there are quite niche-oriented and usually solve a theoretical issue.

I'm looking for sources of conferences or journals (ideally peer-reviewed) on data science that focuses on how to solve a particular business problem. I'm aware some conference attempt to do it in their application track, yet I'm looking for a centralized way to have all them in one place without going through every single conference each time I need to look up something industrial.

Any recommendation on the sources that satisfy my requirements?

Thanks in advance.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

What is the difference between shuffle in fit_generator and shuffle in flow_from_directory?

Noran Asks: What is the difference between shuffle in fit_generator and shuffle in flow_from_directory?
I am using Keras to create a deep learning model and I would like to know that what is the difference between shuffle argument in fit_generator() method and shuffle argument in flow_from_directory() method?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Time complexity for calculating the $LPS$ array (failure function) in KMP algorithm preprocessing

therealak12 Asks: Time complexity for calculating the $LPS$ array (failure function) in KMP algorithm preprocessing
I'm studying the Knuth Morris Pratt pattern searching algorithm from here. I want to know the order of computing the $lps$ array in this algorithm - that is the array of longest proper prefixes that are also suffix. I studied the Wikipedia page for this algorithm and it says this part is of $O(m)$ - $m$ is the length of the pattern being searched. I just don't understand why.

Can anyone help?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Pancake Sorting Graph Recursive Definition

Schmetterling Asks: Pancake Sorting Graph Recursive Definition
I'm having trouble understanding exactly how the graph for Pn (where n = number of pancakes) is defined recursively for n>= 4. I can see obviously that, in the case of n=4, there will be 4 rough copies of the graph where n=3 with additions of 4 in certain places (where, and how is this defined?). But these copies aren't exact, and I can't find any detail on Wikipedia except for that it is indeed recursively defined. I'm asking with a view possibly to be able to generate a graph algorithmically for n>=4 recursively.

Here is a graph for n=4 (so there are 4! / 24 possible configurations of pancakes, and thus 24 nodes in the graph). Here it is for n=4, on this Wikipedia article: https://en.wikipedia.org/wiki/Pancake_graph.

See this Wikipedia article for more on Pancake Sorting - https://en.wikipedia.org/wiki/Pancake_sorting.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

[Solved] How to add projection of your need

Usha Asks: How to add projection of your need
I have to process data from Nepal. Modified Mercator projection(MUTM) is what I need but I can only find Mercator projection. I used the closest mercator projection (WGS 84 /UTM zone 45 N) for my project but the surveyed points don't lie in the correct position. I saw answer to this question for earlier version of QGIS (it was mentioned it works for version below 3.1 or 3.4) which was as follows Steps to use in QGIS- 1.SRS.db: paste this file in C:\Program Files\QGIS 18\apps\qgis\resources

2.ESRI_EXTRA.wkt: paste this file in C:\Program Files\QGIS 18\share\gdal Now you can project map in NEPAL MUTM 81,84 or 87 as per requirement.

The mentioned files were also provided but but I am using QGIS 3.22 and I couldn't find the gdal folder. I am very new to QGIS and Python.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

[Solved] Importing SketchUp (skp) file to ArcGIS Pro

Nirevezs Asks: Importing SketchUp (skp) file to ArcGIS Pro
I've downloaded some 3D data from 3dwarehouse.sketchup.com

Now, I would like to open it in ArcGIS Pro but I cannot find how can to do it.

How can I do this?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

Fire fills the "living" criteria?

  • Kamal Saleh
  • Biology
  • Replies: 0
Kamal Saleh Asks: Fire fills the "living" criteria?
Disclaimer: I think this question fits here since it is about life.

Hello BSE! So I was thinking of fire and the fact that it needed oxygen to breath. I thought of other criteria for life and it seemed like fire fulfilled every sing one. Here are the things that came in my head:

  • Fire eats and grows.
  • Fire breathes.
  • Fire makes waste (smoke).
  • Fire could reproduce (if it makes a strong spark and goes far away).
  • Fire is born and dies.

In fact it seems more alive than viruses. So what makes fire non-living?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.