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...
Asked
Active
Viewed 255 times
-4
-
3Welcome 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 Answers
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.
- 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.
- 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.
- 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