First let's get some imports out of the way:
In [1]:
Copied!
import tensorflow as tf
import fastestimator as fe
from fastestimator import Network, Pipeline, Estimator
from fastestimator.dataset.data import horse2zebra
from fastestimator.op.numpyop.multivariate import Resize
from fastestimator.op.numpyop.univariate import Normalize, ReadImage
from fastestimator.op.tensorop import LambdaOp
from fastestimator.op.tensorop.gradient import GradientOp
from fastestimator.op.tensorop.model import ModelOp
from fastestimator.trace.io import ImageViewer
from fastestimator.trace.xai import GradCAM
from fastestimator.util import BatchDisplay
import tensorflow as tf
import fastestimator as fe
from fastestimator import Network, Pipeline, Estimator
from fastestimator.dataset.data import horse2zebra
from fastestimator.op.numpyop.multivariate import Resize
from fastestimator.op.numpyop.univariate import Normalize, ReadImage
from fastestimator.op.tensorop import LambdaOp
from fastestimator.op.tensorop.gradient import GradientOp
from fastestimator.op.tensorop.model import ModelOp
from fastestimator.trace.io import ImageViewer
from fastestimator.trace.xai import GradCAM
from fastestimator.util import BatchDisplay
Example Data and Pipeline¶
For this tutorial we will use some pictures of zebras with minimal pre-processing. Let's visualize some of the images to see what we're working with.
In [2]:
Copied!
train_data, eval_data = horse2zebra.load_data(batch_size=5)
test_data = eval_data.split(range(5)) # We will just use the first 5 images for our visualizations
pipeline = Pipeline(test_data=test_data,
ops=[ReadImage(inputs="B", outputs="B"),
Resize(image_in="B", image_out="B", height=224, width=224),
Normalize(inputs="B", outputs="B", mean=(0.4914, 0.4822, 0.4465), std=(0.2471, 0.2435, 0.2616)),
])
train_data, eval_data = horse2zebra.load_data(batch_size=5)
test_data = eval_data.split(range(5)) # We will just use the first 5 images for our visualizations
pipeline = Pipeline(test_data=test_data,
ops=[ReadImage(inputs="B", outputs="B"),
Resize(image_in="B", image_out="B", height=224, width=224),
Normalize(inputs="B", outputs="B", mean=(0.4914, 0.4822, 0.4465), std=(0.2471, 0.2435, 0.2616)),
])
In [3]:
Copied!
batch = pipeline.get_results(mode='test')
fig = BatchDisplay(image=batch['B'], title="Zebras")
fig.show()
batch = pipeline.get_results(mode='test')
fig = BatchDisplay(image=batch['B'], title="Zebras")
fig.show()