Method: Chainer::Datasets::CIFAR.preprocess_cifar

Defined in:
lib/chainer/datasets/cifar.rb

.preprocess_cifar(images, labels, withlabel, ndim, scale, device: Chainer::Device.default) ⇒ Object

[View source]

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chainer/datasets/cifar.rb', line 35

def self.preprocess_cifar(images, labels, withlabel, ndim, scale, device: Chainer::Device.default)
  if ndim == 1
    images = images.reshape(images.shape[0], 3072)
  elsif ndim == 3
    images = images.reshape(images.shape[0], 3, 32, 32)
  else
    raise 'invalid ndim for CIFAR dataset'
  end
  xm = device.xm
  images = images.cast_to(xm::SFloat)
  images *= scale / 255.0

  if withlabel
    labels = labels.cast_to(xm::Int32)
    TupleDataset.new(images, labels)
  else
    images
  end
end