-4

ist there a code example on how to do linear regression on a custom image dataset? I have only found examples using the CIFAR dataset...

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • 3
    Welcome to SO; please do take some time to read [What topics can I ask about here?](https://stackoverflow.com/help/on-topic), and notice that questions asking us to *recommend or find a book, tool, software library, tutorial or other off-site resource* are off-topic here. – desertnaut Jan 31 '19 at 15:56

1 Answers1

1

Here's a guide as to how you can make minor modifications to the MNIST example to suit your needs. There may be some fiddling.

  1. Store your data locally as images in a directory under different categories:
train/cats/abc.jpg
train/cats/def.jpg ...
train/dogs/ghi.jpg ...
train/mouse/jkl.jpg ...

analogously for validation
val/cats/...
val/dogs/...

The filenames don't matter, just the directories as these will be use to identify the category.

  1. Update the MNIST example to use the ImageFolderDataset for your test and train data
train_data = mx.gluon.data.vision.datasets.ImageFolderDataset(training_path)
val_data = mx.gluon.data.vision.datasets.ImageFolderDataset(val_path)

Note, you may need to apply a transform to your images.

  1. Replace the network with a single dense layer with no activation and an L2 loss for a linear regression.
net = Dense(number_of_outputs)  # activation=None, use_bias=True by default

(In the code it's lenet instead of net.)

More docs: https://mxnet.incubator.apache.org/versions/master/tutorials/gluon/datasets.html

Hope that helps!

Vishaal
  • 735
  • 3
  • 13