SlideShare a Scribd company logo
1 of 3
Download to read offline
Hello below is my code for MPL image classification. When I try to run the bold segment, I am
given the following error: "default_collate: batch must contain tensors, numpy arrays, numbers,
dicts or lists; found <class 'PIL.Image.Image'>" if someone can help me I would appreciate it.
import torchvision.datasets as datasets
import torch.optim as optim
import torch.utils.data as data
import torch.nn as nn
from torchvision import transforms
train_data = datasets.CIFAR100(root='data', train=True, transform=None, download=True)
test_data = datasets.CIFAR100(root='data', train=False, transform=None, download=True)
class MLP(nn.Module):
def __init__(self, input_size, hidden_size, num_classes):
super(MLP, self).__init__()
self.fc1 = nn.Linear(input_size, hidden_size)
self.relu1 = nn.ReLU()
self.fc2 = nn.Linear(hidden_size, hidden_size)
self.relu2 = nn.ReLU()
self.fc3 = nn.Linear(hidden_size, num_classes)
def forward(self, x):
out = self.fc1(x)
out = self.relu1(out)
out = self.fc2(out)
out = self.relu2(out)
out = self.fc3(out)
return out
input_size = 32 * 32 * 3
hidden_size = 512
num_classes = 100
learning_rate = 0.001
batch_size = 128
num_epochs = 10
model = MLP(input_size, hidden_size, num_classes)
train_loader = data.DataLoader(train_data, batch_size=batch_size, shuffle=True)
test_loader = data.DataLoader(test_data, batch_size=batch_size, shuffle=False)
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=learning_rate)
for epoch in range(num_epochs):
for i, (images, labels) in enumerate(train_loader):
images = images.reshape(-1, input_size).to(device)
labels = labels.to(device)
optimizer.zero_grad()
outputs = model(images)
loss = criterion(outputs, labels)
loss.backward()
Hello below is my code for MPL image classification- When I try to run.pdf

More Related Content

Similar to Hello below is my code for MPL image classification- When I try to run.pdf

Using the code below- I need help with the following 3 things- 1) Writ.pdf
Using the code below- I need help with the following 3 things- 1) Writ.pdfUsing the code below- I need help with the following 3 things- 1) Writ.pdf
Using the code below- I need help with the following 3 things- 1) Writ.pdf
acteleshoppe
 
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
NANDHINIS900805
 
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
Need an detailed analysis of what this code-model is doing- Thanks #St.pdfNeed an detailed analysis of what this code-model is doing- Thanks #St.pdf
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
actexerode
 
Need help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docxNeed help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docx
lauracallander
 
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdfI want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
MattU5mLambertq
 
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdfI want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
GordonF2XPatersonh
 

Similar to Hello below is my code for MPL image classification- When I try to run.pdf (20)

CNN_INTRO.pptx
CNN_INTRO.pptxCNN_INTRO.pptx
CNN_INTRO.pptx
 
Deep learning image classification aplicado al mundo de la moda
Deep learning image classification aplicado al mundo de la modaDeep learning image classification aplicado al mundo de la moda
Deep learning image classification aplicado al mundo de la moda
 
Using the code below- I need help with the following 3 things- 1) Writ.pdf
Using the code below- I need help with the following 3 things- 1) Writ.pdfUsing the code below- I need help with the following 3 things- 1) Writ.pdf
Using the code below- I need help with the following 3 things- 1) Writ.pdf
 
Machine Learning with Tensorflow
Machine Learning with TensorflowMachine Learning with Tensorflow
Machine Learning with Tensorflow
 
From Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerFrom Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow Eager
 
How to Build a Neural Network and Make Predictions
How to Build a Neural Network and Make PredictionsHow to Build a Neural Network and Make Predictions
How to Build a Neural Network and Make Predictions
 
maXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIImaXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VII
 
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
 
Python classes objects
Python classes objectsPython classes objects
Python classes objects
 
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
Need an detailed analysis of what this code-model is doing- Thanks #St.pdfNeed an detailed analysis of what this code-model is doing- Thanks #St.pdf
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
 
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
 
Image classification using cnn
Image classification using cnnImage classification using cnn
Image classification using cnn
 
Deep learning-practical
Deep learning-practicalDeep learning-practical
Deep learning-practical
 
Need help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docxNeed help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docx
 
Introduction to Deep Learning with Python
Introduction to Deep Learning with PythonIntroduction to Deep Learning with Python
Introduction to Deep Learning with Python
 
Machine learning with py torch
Machine learning with py torchMachine learning with py torch
Machine learning with py torch
 
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdfI want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
 
The ABC of Implementing Supervised Machine Learning with Python.pptx
The ABC of Implementing Supervised Machine Learning with Python.pptxThe ABC of Implementing Supervised Machine Learning with Python.pptx
The ABC of Implementing Supervised Machine Learning with Python.pptx
 
The TensorFlow dance craze
The TensorFlow dance crazeThe TensorFlow dance craze
The TensorFlow dance craze
 
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdfI want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
 

More from gaurav444u

Header #include -string- #include -vector- #include -iostream- using.pdf
Header #include -string- #include -vector- #include -iostream-   using.pdfHeader #include -string- #include -vector- #include -iostream-   using.pdf
Header #include -string- #include -vector- #include -iostream- using.pdf
gaurav444u
 
Harvard Case Study- Humana's Bold Goal- 20 Percent Healthier by 2020 -.pdf
Harvard Case Study- Humana's Bold Goal- 20 Percent Healthier by 2020 -.pdfHarvard Case Study- Humana's Bold Goal- 20 Percent Healthier by 2020 -.pdf
Harvard Case Study- Humana's Bold Goal- 20 Percent Healthier by 2020 -.pdf
gaurav444u
 
Help with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdfHelp with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdf
gaurav444u
 

More from gaurav444u (20)

Health Care Unions Find a Voice as the Pandemic Rages - The New York T.pdf
Health Care Unions Find a Voice as the Pandemic Rages - The New York T.pdfHealth Care Unions Find a Voice as the Pandemic Rages - The New York T.pdf
Health Care Unions Find a Voice as the Pandemic Rages - The New York T.pdf
 
Health - Related Questions 1- What three pieces of information are gat.pdf
Health - Related Questions 1- What three pieces of information are gat.pdfHealth - Related Questions 1- What three pieces of information are gat.pdf
Health - Related Questions 1- What three pieces of information are gat.pdf
 
Health Information Technology (HIT) as Electronic Health Record (EHR).pdf
Health Information Technology (HIT) as Electronic Health Record (EHR).pdfHealth Information Technology (HIT) as Electronic Health Record (EHR).pdf
Health Information Technology (HIT) as Electronic Health Record (EHR).pdf
 
Headlands Limited has the following information available regarding it.pdf
Headlands Limited has the following information available regarding it.pdfHeadlands Limited has the following information available regarding it.pdf
Headlands Limited has the following information available regarding it.pdf
 
Header #include -string- #include -vector- #include -iostream- using.pdf
Header #include -string- #include -vector- #include -iostream-   using.pdfHeader #include -string- #include -vector- #include -iostream-   using.pdf
Header #include -string- #include -vector- #include -iostream- using.pdf
 
he method by which glucose is transported into a cell depends on the m.pdf
he method by which glucose is transported into a cell depends on the m.pdfhe method by which glucose is transported into a cell depends on the m.pdf
he method by which glucose is transported into a cell depends on the m.pdf
 
he City Council of Inman Village approved a budget with estimated reve.pdf
he City Council of Inman Village approved a budget with estimated reve.pdfhe City Council of Inman Village approved a budget with estimated reve.pdf
he City Council of Inman Village approved a budget with estimated reve.pdf
 
he department has expanded telehealth and device-monitoring services-.pdf
he department has expanded telehealth and device-monitoring services-.pdfhe department has expanded telehealth and device-monitoring services-.pdf
he department has expanded telehealth and device-monitoring services-.pdf
 
he evolution of eukaryotic cells most likely occurred in many steps- O.pdf
he evolution of eukaryotic cells most likely occurred in many steps- O.pdfhe evolution of eukaryotic cells most likely occurred in many steps- O.pdf
he evolution of eukaryotic cells most likely occurred in many steps- O.pdf
 
Having passed your board exam- you are now qualified to work in the pa.pdf
Having passed your board exam- you are now qualified to work in the pa.pdfHaving passed your board exam- you are now qualified to work in the pa.pdf
Having passed your board exam- you are now qualified to work in the pa.pdf
 
Having been lost in the desert for 2 days without water- Marion is bad.pdf
Having been lost in the desert for 2 days without water- Marion is bad.pdfHaving been lost in the desert for 2 days without water- Marion is bad.pdf
Having been lost in the desert for 2 days without water- Marion is bad.pdf
 
Harvard Case Study- Humana's Bold Goal- 20 Percent Healthier by 2020 -.pdf
Harvard Case Study- Humana's Bold Goal- 20 Percent Healthier by 2020 -.pdfHarvard Case Study- Humana's Bold Goal- 20 Percent Healthier by 2020 -.pdf
Harvard Case Study- Humana's Bold Goal- 20 Percent Healthier by 2020 -.pdf
 
Harry climbed a ladder to trim some trees- While bending too fast- he.pdf
Harry climbed a ladder to trim some trees- While bending too fast- he.pdfHarry climbed a ladder to trim some trees- While bending too fast- he.pdf
Harry climbed a ladder to trim some trees- While bending too fast- he.pdf
 
HELP- Add button wont work-- i would click on the button and that page.pdf
HELP- Add button wont work-- i would click on the button and that page.pdfHELP- Add button wont work-- i would click on the button and that page.pdf
HELP- Add button wont work-- i would click on the button and that page.pdf
 
Help with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdfHelp with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdf
 
help The following information pertains to Ming Corp- at January 1- Ye.pdf
help The following information pertains to Ming Corp- at January 1- Ye.pdfhelp The following information pertains to Ming Corp- at January 1- Ye.pdf
help The following information pertains to Ming Corp- at January 1- Ye.pdf
 
Help Tina identify her strengths- weaknesses- the opportunities presen.pdf
Help Tina identify her strengths- weaknesses- the opportunities presen.pdfHelp Tina identify her strengths- weaknesses- the opportunities presen.pdf
Help Tina identify her strengths- weaknesses- the opportunities presen.pdf
 
Harriet Quarterly wants a 14- return on the $15000 of assets she has i.pdf
Harriet Quarterly wants a 14- return on the $15000 of assets she has i.pdfHarriet Quarterly wants a 14- return on the $15000 of assets she has i.pdf
Harriet Quarterly wants a 14- return on the $15000 of assets she has i.pdf
 
Harriet is described as someone who -was unusual in her ability to coo.pdf
Harriet is described as someone who -was unusual in her ability to coo.pdfHarriet is described as someone who -was unusual in her ability to coo.pdf
Harriet is described as someone who -was unusual in her ability to coo.pdf
 
help please- thank you! i need to know the Virginia Department of Educ.pdf
help please- thank you! i need to know the Virginia Department of Educ.pdfhelp please- thank you! i need to know the Virginia Department of Educ.pdf
help please- thank you! i need to know the Virginia Department of Educ.pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

Hello below is my code for MPL image classification- When I try to run.pdf

  • 1. Hello below is my code for MPL image classification. When I try to run the bold segment, I am given the following error: "default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'>" if someone can help me I would appreciate it. import torchvision.datasets as datasets import torch.optim as optim import torch.utils.data as data import torch.nn as nn from torchvision import transforms train_data = datasets.CIFAR100(root='data', train=True, transform=None, download=True) test_data = datasets.CIFAR100(root='data', train=False, transform=None, download=True) class MLP(nn.Module): def __init__(self, input_size, hidden_size, num_classes): super(MLP, self).__init__() self.fc1 = nn.Linear(input_size, hidden_size) self.relu1 = nn.ReLU() self.fc2 = nn.Linear(hidden_size, hidden_size) self.relu2 = nn.ReLU() self.fc3 = nn.Linear(hidden_size, num_classes) def forward(self, x): out = self.fc1(x) out = self.relu1(out) out = self.fc2(out) out = self.relu2(out) out = self.fc3(out)
  • 2. return out input_size = 32 * 32 * 3 hidden_size = 512 num_classes = 100 learning_rate = 0.001 batch_size = 128 num_epochs = 10 model = MLP(input_size, hidden_size, num_classes) train_loader = data.DataLoader(train_data, batch_size=batch_size, shuffle=True) test_loader = data.DataLoader(test_data, batch_size=batch_size, shuffle=False) criterion = nn.CrossEntropyLoss() optimizer = optim.Adam(model.parameters(), lr=learning_rate) for epoch in range(num_epochs): for i, (images, labels) in enumerate(train_loader): images = images.reshape(-1, input_size).to(device) labels = labels.to(device) optimizer.zero_grad() outputs = model(images) loss = criterion(outputs, labels) loss.backward()