3
$\begingroup$

As some of you may know, CIFAR-10 is a data base which has 60,000 images (which are 32x32 in size) of 10 different categories (airplane, dog, cat, frog, deer, bird, horse, ship, automobile and truck). My idea is to revert the process, i.e I would like to be able to give the program a name (dog, for example) and recieve an image which resembles a that object (the dog, in this case). I am having problems though with the neural network itself and I am not sure of how I should give the input to it.

So, first of all I load CIFAR-10:

cifar10 = ResourceObject["CIFAR-10"]

I also loaded the training data and transformed all the names (airplane, dog, etc) into numbers from 0 to 9 because I think that it is going to be easier if I have those inputs as digits.

rawtraining = 
  ResourceData[cifar10, "TrainingData"] /. {"airplane" -> 0, 
    "dog" -> 1, "cat" -> 2, "frog" -> 3, "deer" -> 4, "bird" -> 5, 
    "horse" -> 6, "ship" -> 7, "automobile" -> 8, "truck" -> 9};

rawtest = 
  ResourceData[cifar10, "TestData"] /. {"airplane" -> 0, "dog" -> 1, 
    "cat" -> 2, "frog" -> 3, "deer" -> 4, "bird" -> 5, "horse" -> 6, 
    "ship" -> 7, "automobile" -> 8, "truck" -> 9};

RandomSample[rawtest, 5]

This is a little sample of how it looks

Afterwards, I just invert the input and the output with this function (I am also converting the image output into data with ImageData):

rawtoGAN[list_] := list[[2]] -> ImageData[list[[1]]]
training = rawtoGAN[#] & /@ rawtraining;
test = rawtoGAN[#] & /@ rawtest;

But the ImageData on my outputs gives a fairly big matrix which encodes the image in RGB parameters. When I try to train the following neural net it always gives me a message saying that the input is incorrect (sometimes it also says the output is incorrect, so I guess I am messing with both).

 generator = 
 NetInitialize[
  NetChain[{256, Ramp, BatchNormalizationLayer[], 512, Ramp, 
    BatchNormalizationLayer[], 1024, Ramp, BatchNormalizationLayer[], 
    32^2, ReshapeLayer[{32, 32}]}, "Input" -> {1, 3}]]

trainedGen = 
 NetTrain[generator, training, ValidationSet -> test, 
  MaxTrainingRounds -> 4]

After "trainedGen", I see a message saying that either my input or my output are bad. I would like to know if anyone has an idea of how I could give proper inputs to my neural network or if I should change it all in order to obtain an image out of a number (the reverse process of CIFAR-10). I hope the explanation is not very confusing, I tried to do my best.

Thank you very much!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.