1

I need a dataset object that contains only images for unsupervised learning in Chainer framework. I am trying to use DatasetMixin for this purpose.

Images is a list containing images.

class SimpleDataset(dataset.DatasetMixin):
    def __init__(self, Images):
        self.Images = Images
    def __len__(self):
        return len(self.Images)
    def get_example(self, i):
        return self.Images[i]

The SimpleDataset Class seems to not able to read the images since when running trainer.run() I am getting error:

call() missing 1 required positional argument: 'x'

Do I need to process the image list furthur before putting it through DatasetMixin Class?

Is there something wrong with using DatasetMixin to feed just images this way?

What can I do to feed just images(without any labels or other things) to my model?

class AutoEncoder(chainer.Chain):
    def __init__(self, n_in, n_out):
        super(AutoEncoder, self).__init__(
            l1 = L.Linear(n_in, n_out),
            l2 = L.Linear(n_out, n_in)
    )
        self.add_param('decoder_bias', n_in)
        self.decoder_bias.data[...] = 0

    def __call__(self, x):
        h1 = F.dropout(self.l1(x))
        h2 = F.linear(h1, F.transpose(self.l1.W), self.decoder_bias)
        return F.sigmoid(h2)

    def encode(self, x):
        return F.dropout(self.l1(x))

    def decode(self, x):
        return self.l2(x)

model = L.Classifier(AutoEncoder(40000, 1000), lossfun=F.mean_squared_error)
model.compute_accuracy = False
TulakHord
  • 422
  • 7
  • 15
  • Can you share your model definition as well? Did you use `Classifier` or some wrapper model? Dataset definition itself looks ok. – corochann Jun 03 '19 at 05:46
  • Hi @corochann, I have edited the question to add model definition. – TulakHord Jun 03 '19 at 06:12
  • Since I used classifier, I tried using model = AutoEncoder(x, y). In this case the error is AttributeError: 'NoneType' object has no attribute 'dtype' – TulakHord Jun 03 '19 at 06:45

1 Answers1

0

If you are using Classifier, the dataset need to return in the format x0, x1, ... xk, y where x0, x1, ... xk will be fed into the predictor (in this case it is AutoEncoder class), and its output value y_pred and actual y is used for loss calculation specified by lossfun.

In your case the answer y is also same with input. I think you can write following to return x and y which is actually same:

def get_example(self, i):
    return self.Images[i], self.Images[i]
corochann
  • 1,604
  • 1
  • 13
  • 24