Vision¶
TorchVisionProblem ¶
Bases: Problem
TorchVision Problem for Computer Vision Optimization.
Evaluates the parameters of a classification network on random batches of an
image dataset. A solution is a PyTree of network parameters. The constructor
downloads the dataset to ~/data if needed and loads the full train and test
splits as JAX arrays, with images in channel-last layout.
Parameters:
-
task_name(str) –Name of the dataset:
"MNIST","FashionMNIST","CIFAR10"or"SVHN". Any other value raises aValueError. -
network(Module) –Flax module called as
network.apply(network_params, images, key)that returns the class logits for a batch of images, e.g.CNNfromevosax.problems.networkswithidentity_output_fn. -
batch_size(int, default:1024) –Number of images sampled for every
evalcall.
Note
Requires the optional torch and torchvision packages.
References
eval ¶
Evaluate a population of networks on a batch of the train split.
One batch of batch_size images is sampled without replacement from the
train split and used for all population members.
Parameters:
-
key(Array) –PRNG key.
-
solutions(Population) –Population of network parameters, a PyTree with a leading population axis on every leaf.
-
state(State) –Current problem state.
Returns:
-
tuple[Fitness, State, Metrics]–A tuple
(fitness, state, info).fitnessis the mean softmax cross-entropy loss of each member on the batch (lower is better).statehas its counter incremented.info["accuracy"]is the classification accuracy of each member on the batch.
eval_test ¶
Evaluate a population of networks on a batch of the test split.
One batch of batch_size images is sampled without replacement from the
test split and used for all population members.
Parameters:
-
key(Array) –PRNG key.
-
solutions(Population) –Population of network parameters, a PyTree with a leading population axis on every leaf.
-
state(State) –Current problem state.
Returns:
-
tuple[Fitness, State, Metrics]–A tuple
(fitness, state, info).fitnessis the mean softmax cross-entropy loss of each member on the batch (lower is better).statehas its counter incremented.info["accuracy"]is the classification accuracy of each member on the batch.
sample ¶
Sample network parameters.
Initializes network on a batch of batch_size train images.
Parameters:
-
key(Array) –PRNG key.
Returns:
-
Solution–A PyTree of network parameters.
get_mnist ¶
Get the MNIST dataset.
Returns:
-
datasets(tuple) –A tuple
(dataset_train, dataset_test, loader_train, loader_test)of TorchVision datasets and PyTorch data loaders. Each loader yields its whole split as a single batch.
get_fashion_mnist ¶
Get the Fashion MNIST dataset.
Returns:
-
datasets(tuple) –A tuple
(dataset_train, dataset_test, loader_train, loader_test)of TorchVision datasets and PyTorch data loaders. Each loader yields its whole split as a single batch.
get_cifar10 ¶
Get the CIFAR-10 dataset.
Returns:
-
datasets(tuple) –A tuple
(dataset_train, dataset_test, loader_train, loader_test)of TorchVision datasets and PyTorch data loaders. Each loader yields its whole split as a single batch.
get_svhn ¶
Get the SVHN dataset.
Returns:
-
datasets(tuple) –A tuple
(dataset_train, dataset_test, loader_train, loader_test)of TorchVision datasets and PyTorch data loaders. Each loader yields its whole split as a single batch.