Coder Social home page Coder Social logo

4_customized_image_classifier's Introduction

Hi there ๐Ÿ‘‹, i am starlee

starlee's GitHub stats

4_customized_image_classifier's People

Contributors

iamstarlee avatar

Watchers

 avatar

4_customized_image_classifier's Issues

Expected more than 1 value per channel when training, got input size torch.Size([1, **])

what does BatchNorm1d do mathematically?
try and write down the equation for the case of batch_size=1 and you'll understand why PyTorch is angry with you.

How to solve it?
It is simple: BatchNorm has two "modes of operation": one is for training where it estimates the current batch's mean and variance (this is why you must have batch_size>1 for training).
The other "mode" is for evaluation: it uses accumulated mean and variance to normalize new inputs without re-estimating the mean and variance. In this mode, there are no problems processing samples one by one.

When evaluating your model use model.eval() before and model.train() after.

When the model is in its "training phase" it should be in model.train() state, when evaluating/testing the model it should be in model.eval() state. In your code, these two phases are a little mixed in the main loop. But basically, the code in that loop under torch.no_grad() is an evaluation code, you should have model.eval() at the beginning and switch back to model.train() after it

AttributeError: 'tuple' object has no attribute 'to'

It literally means that the tuple class in Python doesn't have a method called to. Since you're trying to put your labels onto your device, just do labels = torch.tensor(labels).to(device).

If you don't want to do this, you can change the way the DataLoader works by making it return your labels as a PyTorch tensor rather than a tuple.

Since the labels seem to be strings, I would convert them to one-hot encoded vectors first:
import torch labels_unique = set(labels) keys = {key: value for key, value in zip(labels_unique, range(len(labels_unique)))} labels_onehot = torch.zeros(size=(len(labels), len(keys))) for idx, label in enumerate(labels_onehot): labels_onehot[idx][keys[label]] = 1 labels_onehot = labels.to(device)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.