Did you add this line as well?
        # remove invalid targets
        self.mnist_targets_1 = self.mnist_targets_1[self.mnist_targets_1%2==0]

This would remove the unwanted indices and no KeyError should be raised.