diff --git a/alibi/explainers/counterfactual/cf_adversarial.py b/alibi/explainers/counterfactual/cf_adversarial.py index e22876ef5..acbd6227b 100644 --- a/alibi/explainers/counterfactual/cf_adversarial.py +++ b/alibi/explainers/counterfactual/cf_adversarial.py @@ -9,22 +9,122 @@ logger = logging.getLogger(__name__) +def _define_func(predict_fn, x, target_class): + + x_shape_batch_format = (1,) + x.shape + + if target_class == 'other': + def func(): + pass + else: + if target_class == 'same': + target_class = np.argmax(predict_fn(x), axis=1)[0] + + def func(x, target_class=target_class): + #print(target_class) + return predict_fn(x)[:, target_class] + + return func, target_class + + +def _calculate_funcgradx(func, x, epsilon=1.0): + + x = x.reshape(x.shape[1:]) + x_shape = x.shape + + x = x.flatten() + X_plus, X_minus = [], [] + for i in range(len(x)): + x_plus, x_minus = np.copy(x), np.copy(x) + x_plus[i] += epsilon + x_minus[i] -= epsilon + x_plus, x_minus = x_plus.reshape(x_shape), x_minus.reshape(x_shape) + X_plus.append(x_plus) + X_minus.append(x_minus) + + X_plus = np.asarray(X_plus) + X_minus = np.asarray(X_minus) + + gradients = (func(X_plus) - func(X_minus)) / (2 * epsilon) + + return gradients + + +def _define_metric_loss(metric, x_0): + + def _metric_loss(x): + batch_size = x.shape[0] + distances = [] + for i in range(batch_size): + distances.append(metric(x[i].flatten(), x_0.flatten())) + return np.asarray(distances) + + return _metric_loss + + +def _calculate_watcher_grads(x, func, metric, x_0, target_probability, _lam, _norm, + epsilon_func=1.0, epsilon_metric=1e-10): + + x_shape_batch_format = (1,) + x.shape + preds = func(x) + metric_loss = _define_metric_loss(metric, x_0) + + funcgradx = _calculate_funcgradx(func, x, epsilon=epsilon_func) + metricgradx = _calculate_funcgradx(metric_loss, x, epsilon=epsilon_metric) + + gradients_0 = (1 - _lam) * 2 * (preds[0] - target_probability) * funcgradx + gradients_1 = _lam * _norm * metricgradx + gradients = gradients_0 + gradients_1 + + return gradients + + +def minimize_watcher(predict_fn, metric, x_i, x_0, target_class, target_probability, + epsilon_func=5.0, epsilon_metric=0.1, maxiter=50, + initial_lam=0.0, lam_step=0.001, final_lam=1.0, lam_how='adiabatic', + norm=1.0, lr=50.0): + x_shape = x_i.shape + x_shape_batch_format = (1,) + x_i.shape + func, target_class = _define_func(predict_fn, x_0, target_class) + for i in range(maxiter): + if lam_how == 'fixed': + _lam = initial_lam + elif lam_how == 'adiabatic': + _lam = (i / maxiter) * (final_lam - initial_lam) + gradients = _calculate_watcher_grads(x_i, func, metric, x_0, target_probability, + _lam, norm, + epsilon_func=epsilon_func, + epsilon_metric=epsilon_metric) + + x_i = (x_i.flatten() - lr * gradients).reshape(x_shape) + if i % 1 == 0: + #print('Target class: {}'.format(target_class)) + #print('Proba:', predict_fn(x_i)[:, target_class]) + logger.debug('Target class: {}'.format(target_class)) + logger.debug('Proba: {}'.format(predict_fn(x_i)[:, target_class][0])) + return x_i + + class CounterFactualAdversarialSearch: """ """ def __init__(self, predict_fn: Callable, - target_probability: float = 0.5, # TODO what should be default? metric: Union[Callable, str] = 'l1_distance', # TODO should transition to mad_distance + target_class: Union[int, str] = 'same', + target_probability: float = 0.5, # TODO what should be default? tolerance: float = 0, + epsilon_func: float = 5, + epsilon_metric: float = 0.1, maxiter: int = 300, - method: str = 'OuterBoundary', + method: str = 'Wachter', initial_lam: float = 0, lam_step: float = 0.1, - max_lam: float = 1, + final_lam: float = 1, + lam_how: str = 'fixed', # flip_threshold: float = 0.5, - optimizer: Optional[str] = None) -> None: + lr: float = 50.0) -> None: """ Parameters @@ -55,19 +155,50 @@ def __init__(self, TODO """ self.predict_fn = predict_fn + self._metric_distance = _metric_distance_func(metric) + self.target_class = target_class self.target_probability = target_probability - self.metric = metric + self.epsilon_func = epsilon_func + self.epsilon_metric = epsilon_metric self.tolerance = tolerance self.maxiter = maxiter self.method = method - self.lam = initial_lam + self.initial_lam = initial_lam self.lam_step = lam_step - self.max_lam = max_lam + self.final_lam = final_lam + self.lam_how = lam_how self.flip_threshold = flip_threshold - self.optimizer = optimizer - + self.lr = lr + #self.optimizer = optimizer + self.metric = metric # create the metric distance function - self._metric_distance = _metric_distance_func(metric) + + def _initialize(self, X, initialization): + + if initialization is None: + print('init is none') + initial_instance = X + + else: + if hasattr(self, 'f_ranges') and hasattr(self, '_samples'): + if initialization == 'random_from_train_set': + print('random_from_train_set') + initial_instance = np.random.permutation(self._samples)[0].reshape(X.shape) + elif initialization == 'random_uniform': + print('random_uniform with f_ranges') + initial_instance = np.random.uniform(low=[t[0] for t in self.f_ranges], + high=[t[1] for t in self.f_ranges], + size=X.flatten().shape).reshape(X.shape) + else: + raise NameError('initialization method {} not implemented'.format(initialization)) + else: + if initialization == 'random_uniform': + print('random_uniform. No f_ranges') + initial_instance = np.random.uniform(size=X.shape) + else: + raise NameError('initialization method {} not implemented'.format(initialization)) + + return initial_instance def fit(self, X_train, y_train=None, dataset_sample_size=5000): """ @@ -82,24 +213,34 @@ def fit(self, X_train, y_train=None, dataset_sample_size=5000): nb of data points to sample from training data """ - self._lam = self.lam + #self._lam = self.lam self.f_ranges = _calculate_franges(X_train) self.mads = robust.mad(X_train, axis=0) + 10e-10 if dataset_sample_size is not None: self._samples = np.random.permutation(X_train)[:dataset_sample_size] else: self._samples = X_train - _distances = [self._metric_distance(self._samples[i], np.roll(self._samples, 1, axis=0)[i]) + + _distances = [self._metric_distance(self._samples[i].flatten(), np.roll(self._samples, 1, axis=0)[i].flatten()) for i in range(self._samples.shape[0])] self._norm = 1.0 / max(_distances) - def explain(self, X: np.ndarray, nb_instances: int = 2, return_as: str = 'all') -> dict: + def explain(self, X: np.ndarray, + initialization: str = 'random_uniform', + nb_instances: int = 2, + return_as: str = 'all') -> dict: """ Parameters ---------- X instance to explain + initialization + initialization method for minimization + nb_instances + number of instances to generate + return_as + how to return counterfactuals Returns ------- @@ -107,76 +248,45 @@ def explain(self, X: np.ndarray, nb_instances: int = 2, return_as: str = 'all') counterfactual instance serving as an explanation """ - probas_x = self.predict_fn(X) - # probas_x = _predict(self.model, X) - pred_class = np.argmax(probas_x, axis=1)[0] - # print(pred_class) - max_proba_x = probas_x[:, pred_class] + if X.shape[0] != 1: + X = X.reshape((1,)+X.shape) + probas = self.predict_fn(X) + class_x = np.argmax(probas, axis=1)[0] + proba_x = probas[:, class_x] cf_instances = {'idx': [], 'vector': [], 'distance_from_orig': []} # type: Dict[str, list] for i in range(nb_instances): if self.method == 'Wachter' or self.method == 'OuterBoundary': - cond = False - _maxiter = self.maxiter - # initial_instance = np.random.permutation(self._samples)[0] - initial_instance = X - - def _countefactual_loss(x): - pred_tmp = self.predict_fn(x.reshape(X.shape))[:, pred_class] - # pred_tmp = _predict(self.model, x.reshape(X.shape))[:, pred_class] - # print(pred_class, pred_tmp) - loss_0 = self._lam * (pred_tmp - self.target_probability) ** 2 - loss_1 = (1 - self._lam) * self._norm * self._metric_distance(x, X.flatten()) - # print(loss_0,loss_1,self._lam) - return loss_0 + loss_1 - - def _contrains_diff(x): - pred_tmp = self.predict_fn(x.reshape(X.shape))[:, pred_class] - # pred_tmp = _predict(self.model, x.reshape(X.shape))[:, pred_class] - return -(abs(pred_tmp - self.target_probability)) + self.tolerance + initial_instance = self._initialize(X, initialization) + + logger.debug('Starting minimization') t_0 = time() - while not cond: - logger.debug('Starting minimization with Lambda = {}'.format(self._lam)) - cons = ({'type': 'ineq', 'fun': _contrains_diff}) - - res = minimize(_countefactual_loss, initial_instance, constraints=cons, - method=self.optimizer, options={'maxiter': _maxiter}) - probas_exp = self.predict_fn(res.x.reshape(X.shape)) - # probas_exp = _predict(self.model, res.x.reshape(X.shape)) - pred_class_exp = np.argmax(probas_exp, axis=1)[0] - # print('++++++++++++++++++++++', pred_class_exp, probas_exp) - max_proba_exp = probas_exp[:, pred_class_exp] - probas_original = probas_exp[:, pred_class] - cond = _contrains_diff(res.x) >= 0 - - logger.debug('Loss:', res.fun) - logger.debug('Constraint fullfilled:', cond) - - initial_instance = res.x - logger.debug('_maxiter: %s', _maxiter) - - self._lam += self.lam_step - if _maxiter > self.maxiter or self._lam > self.max_lam: - logger.debug(self._lam, 'Stopping minimization') - self._lam = self.lam - cond = True - if self._lam > self.max_lam - self.lam_step: - _maxiter = 1 * self.maxiter - - logger.debug('Minimization time: ', time() - t_0) + x_min = minimize_watcher(self.predict_fn, self._metric_distance, initial_instance, X, + target_class=self.target_class, target_probability=self.target_probability, + epsilon_func=self.epsilon_func,epsilon_metric=self.epsilon_metric, + initial_lam=self.initial_lam, final_lam=self.final_lam, + lam_how=self.lam_how, maxiter=self.maxiter, lr=self.lr) + + probas_cf = self.predict_fn(x_min.reshape(X.shape)) + class_cf = np.argmax(probas_cf, axis=1)[0] + proba_cf = probas_cf[:, class_cf] + proba_cf_class_x = probas_cf[:, class_x] + + logger.debug('Minimization time: {}'.format(time() - t_0)) + cf_instances['idx'].append(i) - cf_instances['vector'].append(res.x.reshape(X.shape)) - cf_instances['distance_from_orig'].append(self._metric_distance(res.x, X.flatten())) + cf_instances['vector'].append(x_min.reshape(X.shape)) + cf_instances['distance_from_orig'].append(self._metric_distance(x_min.flatten(), X.flatten())) logger.debug('Counterfactual instance {} of {} generated'.format(i, nb_instances - 1)) logger.debug( - 'Original instance predicted class: {} with probability {}:'.format(pred_class, max_proba_x)) - logger.debug('Countfact instance original class probability: {}'.format(probas_original)) + 'Original instance predicted class: {} with probability {}:'.format(class_x, proba_x)) + logger.debug('Countfact instance original class probability: {}'.format(proba_cf_class_x)) logger.debug('Countfact instance predicted class: ' - '{} with probability {}:'.format(pred_class_exp, max_proba_exp)) - logger.debug('Original instance shape', X.shape) + '{} with probability {}:'.format(class_cf, proba_cf)) + logger.debug('Original instance shape {}'.format(X.shape)) self.cf_instances = cf_instances diff --git a/examples/counterfactuals_mnist.ipynb b/examples/counterfactuals_mnist.ipynb new file mode 100644 index 000000000..298076b12 --- /dev/null +++ b/examples/counterfactuals_mnist.ipynb @@ -0,0 +1,970 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "DEBUG:matplotlib.pyplot:Loaded backend module://ipykernel.pylab.backend_inline version unknown.\n" + ] + } + ], + "source": [ + "import sys\n", + "#sys.path.append('../alibi/explainers/counterfactual/')\n", + "import logging\n", + "logging.basicConfig(level=logging.DEBUG)\n", + "import pandas as pd\n", + "import numpy as np\n", + "from scipy.spatial.distance import cityblock\n", + "from scipy.optimize import minimize\n", + "from sklearn import svm, datasets\n", + "from sklearn.model_selection import cross_val_score\n", + "from alibi.explainers import CounterFactualAdversarialSearch\n", + "from matplotlib.pyplot import imshow\n", + "import importlib\n", + "#sys.path.append('../alibi/explainers/counterfactual/')\n", + "#import cf_adversarial as counterfactuals\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Mnist" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING: Logging before flag parsing goes to stderr.\n", + "I0408 14:29:04.217362 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 14:29:04.231672 140735836812160 font_manager.py:1254] findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans ('/Users/Gigio/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans.ttf') with score of 0.050000.\n", + "I0408 14:29:04.257077 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 14:29:04.285659 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 14:29:04.311816 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 14:29:04.327574 140735836812160 _base.py:2515] update_title_pos\n" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSU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PzN4ctu1cM3vazP6W/RxxmbSCervTzP4ve+xeM7NrC+ptupk9a2Y7zWyHmf1ntr3Qxy7RVyGPW8uf9pvZGEnvSrpG0oCklyQtdve3WtpIBWbWL6nk7oXPCZvZVZIOSnrE3Wdk2+6T9LG7r8j+4Zzk7r9ok97ulHSw6JWbswVlpg1fWVrSAkk/UYGPXaKv61XA41bEmX+mpPfc/QN3/6ekP0iaX0Afbc/dn5P08Qmb50tal91ep6G/PC1Xobe24O573P2V7PZnko6vLF3oY5foqxBFhP98SbuG3R9Qey357ZK2mtnLZtZTdDMjmJotm358+fQpBfdzoqorN7fSCStLt81jV8+K13krIvwjrf7TTlMOs9z9Uknfl/Tz7OktalPTys2tMsLK0m2h3hWv81ZE+AckTR92/+uSdhfQx4jcfXf2c5+kTWq/1Yf3Hl8kNfu5r+B+/qWdVm4eaWVptcFj104rXhcR/pckXWhm3zCzcZJ+JGlLAX18hZmdnb0RIzM7W9Jctd/qw1skLcluL5G0ucBevqRdVm6utLK0Cn7s2m3F60I+5JNNZdwvaYykNe7+Xy1vYgRm9k0Nne2loUVMf19kb2b2qKRuDV31tVfSLyU9IemPki6Q9HdJP3T3lr/xVqG3bg09df3Xys3HX2O3uLcrJf2vpDckHcs292ro9XVhj12ir8Uq4HHjE35AUHzCDwiK8ANBEX4gKMIPBEX4gaAIPxAU4QeCIvxAUP8PRZ8Vlgh2BcUAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "import tensorflow as tf\n", + "(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()\n", + "imshow(x_train[0],cmap='Greys')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "W0408 14:29:07.074733 140735836812160 deprecation.py:506] From /Users/Gigio/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/init_ops.py:1257: calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Call initializer instance with the dtype argument instead of passing it to the constructor\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x_train shape: (60000, 28, 28, 1)\n", + "Number of images in x_train 60000\n", + "Number of images in x_test 10000\n" + ] + } + ], + "source": [ + "x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)\n", + "x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)\n", + "input_shape = (28, 28, 1)\n", + "# Making sure that the values are float so that we can get decimal points after division\n", + "x_train = x_train.astype('float32')\n", + "x_test = x_test.astype('float32')\n", + "# Normalizing the RGB codes by dividing it to the max RGB value.\n", + "x_train /= 255\n", + "x_test /= 255\n", + "print('x_train shape:', x_train.shape)\n", + "print('Number of images in x_train', x_train.shape[0])\n", + "print('Number of images in x_test', x_test.shape[0])\n", + "initial_instace = np.random.permutation(x_train)[:1]\n", + "\n", + "input = tf.keras.Input(shape=(28,28,1),name='input_part')\n", + "out=tf.keras.layers.Conv2D(32, (5, 5), activation='relu')(input)\n", + "out=tf.keras.layers.MaxPooling2D(pool_size=(2, 2))(out)\n", + "out=tf.keras.layers.Dropout(0.2)(out)\n", + "out=tf.keras.layers.Flatten()(out)\n", + "out=tf.keras.layers.Dense(128, activation='relu')(out)\n", + "out=tf.keras.layers.Dense(10,activation='softmax')(out)\n", + "\n", + "model = tf.keras.Model(input, out)\n", + "\n", + "model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epoch 1/2\n", + "60000/60000 [==============================] - 16s 274us/sample - loss: 0.1352 - acc: 0.9606\n", + "Epoch 2/2\n", + "60000/60000 [==============================] - 19s 323us/sample - loss: 0.0493 - acc: 0.9847\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.fit(x_train,tf.keras.utils.to_categorical(y_train),epochs=2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Minimization" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(28, 28, 1)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X=x_train[54]\n", + "X.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "import alibi.explainers.counterfactual.cf_adversarial as counterfactuals" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 124, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "importlib.reload(counterfactuals)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 125, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1.1420827e-10, 1.0617840e-07, 6.9988083e-08, 1.0176440e-05,\n", + " 1.2435452e-02, 9.8999976e-07, 1.7569269e-12, 4.3955473e-03,\n", + " 9.2290936e-04, 9.8223478e-01]], dtype=float32)" + ] + }, + "execution_count": 125, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.predict(X.reshape((1,)+X.shape))" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.argmax(model.predict(X.reshape((1,)+X.shape)))" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [], + "source": [ + "import logging\n", + "logger = logging.getLogger()\n", + "logger.setLevel(logging.DEBUG)\n", + "cf = counterfactuals.CounterFactualAdversarialSearch(model.predict,\n", + " target_class=4,target_probability=1.0,\n", + " maxiter=200, initial_lam=0, final_lam=0.01, lam_how='adiabatic',\n", + " lr=10)\n", + "cf.fit(x_train,y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "I0408 15:14:34.109055 140735836812160 cf_adversarial.py:263] Starting minimization\n", + "I0408 15:14:34.269900 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:34.273211 140735836812160 cf_adversarial.py:104] Proba: 1.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "init is none\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "I0408 15:14:34.432443 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:34.436082 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:34.598999 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:34.601943 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:34.761479 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:34.764475 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:34.920355 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:34.923579 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:35.078097 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:35.081321 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:35.237734 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:35.240962 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:35.396411 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:35.399405 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:35.552784 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:35.556052 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:35.712954 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:35.716282 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:35.869077 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:35.872370 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:36.024064 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:36.027251 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:36.180278 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:36.183716 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:36.337399 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:36.340138 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:36.493656 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:36.497039 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:36.652470 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:36.655758 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:36.809458 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:36.813067 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:36.970263 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:36.973006 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:37.125488 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:37.128534 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:37.283069 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:37.286411 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:37.442353 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:37.445505 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:37.605370 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:37.608083 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:37.765199 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:37.768383 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:37.925736 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:37.929849 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:38.089161 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:38.092370 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:38.251795 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:38.254628 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:38.416698 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:38.420560 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:38.575986 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:38.579130 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:38.739127 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:38.742511 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:38.908461 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:38.911922 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:39.075221 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:39.078149 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:39.244596 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:39.248606 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:39.415227 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:39.418398 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:39.587455 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:39.590478 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:39.762640 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:39.765727 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:39.941178 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:39.944299 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:40.130321 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:40.133353 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:40.315325 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:40.318957 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:40.502926 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:40.506766 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:40.691855 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:40.695342 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:40.889660 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:40.892908 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:41.084490 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:41.088045 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:41.279752 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:41.282998 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:41.477999 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:41.481292 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:41.677469 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:41.680774 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:41.880755 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:41.884164 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:42.085616 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:42.089341 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:42.289808 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:42.293221 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:42.497020 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:42.500361 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:42.709124 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:42.712870 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:42.920410 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:42.923759 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:43.133796 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:43.137320 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:43.347795 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:43.351868 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:43.564720 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:43.568855 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:43.783204 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:43.786699 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:44.010653 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:44.015017 140735836812160 cf_adversarial.py:104] Proba: 1.0\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "I0408 15:14:44.233182 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:44.237456 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:44.451136 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:44.455049 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:44.669070 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:44.673414 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:44.896901 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:44.900536 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:45.114968 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:45.118443 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:45.338541 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:45.342329 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:45.557037 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:45.560569 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:45.777452 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:45.781663 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:46.001141 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:46.004815 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:46.229117 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:46.233373 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:46.464858 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:46.468553 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:46.691751 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:46.695436 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:46.920401 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:46.924378 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:47.149590 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:47.153199 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:47.377968 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:47.381556 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:47.604706 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:47.608280 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:47.832372 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:47.836470 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:48.059965 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:48.063501 140735836812160 cf_adversarial.py:104] Proba: 0.9999998807907104\n", + "I0408 15:14:48.287446 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:48.291189 140735836812160 cf_adversarial.py:104] Proba: 0.9999995231628418\n", + "I0408 15:14:48.514802 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:48.518499 140735836812160 cf_adversarial.py:104] Proba: 0.9999985694885254\n", + "I0408 15:14:48.741673 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:48.745413 140735836812160 cf_adversarial.py:104] Proba: 0.9999943971633911\n", + "I0408 15:14:48.969013 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:48.972720 140735836812160 cf_adversarial.py:104] Proba: 0.9999749660491943\n", + "I0408 15:14:49.194797 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:49.198408 140735836812160 cf_adversarial.py:104] Proba: 0.999884843826294\n", + "I0408 15:14:49.421607 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:49.425254 140735836812160 cf_adversarial.py:104] Proba: 0.9994682669639587\n", + "I0408 15:14:49.650196 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:49.653775 140735836812160 cf_adversarial.py:104] Proba: 0.9974935054779053\n", + "I0408 15:14:49.877307 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:49.880980 140735836812160 cf_adversarial.py:104] Proba: 0.9892237186431885\n", + "I0408 15:14:50.105466 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:50.109074 140735836812160 cf_adversarial.py:104] Proba: 0.9808130860328674\n", + "I0408 15:14:50.334183 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:50.337817 140735836812160 cf_adversarial.py:104] Proba: 0.9848695993423462\n", + "I0408 15:14:50.561940 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:50.565605 140735836812160 cf_adversarial.py:104] Proba: 0.9674014449119568\n", + "I0408 15:14:50.789267 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:50.792906 140735836812160 cf_adversarial.py:104] Proba: 0.9939782619476318\n", + "I0408 15:14:51.017701 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:51.021378 140735836812160 cf_adversarial.py:104] Proba: 0.9076998233795166\n", + "I0408 15:14:51.246912 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:51.250487 140735836812160 cf_adversarial.py:104] Proba: 0.9999966621398926\n", + "I0408 15:14:51.476180 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:51.479850 140735836812160 cf_adversarial.py:104] Proba: 0.9998692274093628\n", + "I0408 15:14:51.704490 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:51.708122 140735836812160 cf_adversarial.py:104] Proba: 0.9953824877738953\n", + "I0408 15:14:51.931791 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:51.935431 140735836812160 cf_adversarial.py:104] Proba: 0.906200647354126\n", + "I0408 15:14:52.161988 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:52.165652 140735836812160 cf_adversarial.py:104] Proba: 0.9999967813491821\n", + "I0408 15:14:52.389513 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:52.393620 140735836812160 cf_adversarial.py:104] Proba: 0.9998584985733032\n", + "I0408 15:14:52.617999 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:52.621587 140735836812160 cf_adversarial.py:104] Proba: 0.9945787191390991\n", + "I0408 15:14:52.846354 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:52.849965 140735836812160 cf_adversarial.py:104] Proba: 0.897117555141449\n", + "I0408 15:14:53.075777 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:53.079461 140735836812160 cf_adversarial.py:104] Proba: 0.9999988079071045\n", + "I0408 15:14:53.307712 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:53.312037 140735836812160 cf_adversarial.py:104] Proba: 0.999946117401123\n", + "I0408 15:14:53.536586 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:53.540246 140735836812160 cf_adversarial.py:104] Proba: 0.9974959492683411\n", + "I0408 15:14:53.765815 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:53.769562 140735836812160 cf_adversarial.py:104] Proba: 0.9241563677787781\n", + "I0408 15:14:53.997278 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:54.000936 140735836812160 cf_adversarial.py:104] Proba: 0.9999634027481079\n", + "I0408 15:14:54.228334 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:54.231960 140735836812160 cf_adversarial.py:104] Proba: 0.9977116584777832\n", + "I0408 15:14:54.463667 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:54.467519 140735836812160 cf_adversarial.py:104] Proba: 0.9151783585548401\n", + "I0408 15:14:54.707962 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:54.711740 140735836812160 cf_adversarial.py:104] Proba: 0.9999880790710449\n", + "I0408 15:14:54.954266 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:54.957931 140735836812160 cf_adversarial.py:104] Proba: 0.9991024732589722\n", + "I0408 15:14:55.197022 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:55.200656 140735836812160 cf_adversarial.py:104] Proba: 0.9545319080352783\n", + "I0408 15:14:55.439834 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:55.443575 140735836812160 cf_adversarial.py:104] Proba: 0.9975415468215942\n", + "I0408 15:14:55.680494 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:55.684267 140735836812160 cf_adversarial.py:104] Proba: 0.8901564478874207\n", + "I0408 15:14:55.921546 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:55.925311 140735836812160 cf_adversarial.py:104] Proba: 0.9999995231628418\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "I0408 15:14:56.162927 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:56.166736 140735836812160 cf_adversarial.py:104] Proba: 0.9999563694000244\n", + "I0408 15:14:56.397831 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:56.401680 140735836812160 cf_adversarial.py:104] Proba: 0.9966756105422974\n", + "I0408 15:14:56.633808 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:56.638131 140735836812160 cf_adversarial.py:104] Proba: 0.8738682866096497\n", + "I0408 15:14:56.870846 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:56.874582 140735836812160 cf_adversarial.py:104] Proba: 0.9999998807907104\n", + "I0408 15:14:57.106560 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:57.110284 140735836812160 cf_adversarial.py:104] Proba: 0.9999938011169434\n", + "I0408 15:14:57.346108 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:57.349896 140735836812160 cf_adversarial.py:104] Proba: 0.9994671940803528\n", + "I0408 15:14:57.581331 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:57.585091 140735836812160 cf_adversarial.py:104] Proba: 0.9654924869537354\n", + "I0408 15:14:57.818477 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:57.822249 140735836812160 cf_adversarial.py:104] Proba: 0.9885802865028381\n", + "I0408 15:14:58.053168 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:58.056943 140735836812160 cf_adversarial.py:104] Proba: 0.8400620818138123\n", + "I0408 15:14:58.287618 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:58.291497 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:14:58.522342 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:58.526042 140735836812160 cf_adversarial.py:104] Proba: 0.9999998807907104\n", + "I0408 15:14:58.758756 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:58.762542 140735836812160 cf_adversarial.py:104] Proba: 0.9999873638153076\n", + "I0408 15:14:58.995630 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:58.999541 140735836812160 cf_adversarial.py:104] Proba: 0.9988709092140198\n", + "I0408 15:14:59.231483 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:59.235254 140735836812160 cf_adversarial.py:104] Proba: 0.9233440160751343\n", + "I0408 15:14:59.466940 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:59.470761 140735836812160 cf_adversarial.py:104] Proba: 0.9999549388885498\n", + "I0408 15:14:59.703318 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:59.707010 140735836812160 cf_adversarial.py:104] Proba: 0.9927359819412231\n", + "I0408 15:14:59.940010 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:14:59.943737 140735836812160 cf_adversarial.py:104] Proba: 0.7800694108009338\n", + "I0408 15:15:00.177125 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:00.181300 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:00.413594 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:00.417295 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:00.649917 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:00.653669 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:00.890375 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:00.894055 140735836812160 cf_adversarial.py:104] Proba: 0.9999983310699463\n", + "I0408 15:15:01.127629 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:01.131336 140735836812160 cf_adversarial.py:104] Proba: 0.9998548030853271\n", + "I0408 15:15:01.365530 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:01.369410 140735836812160 cf_adversarial.py:104] Proba: 0.9868339896202087\n", + "I0408 15:15:01.604506 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:01.608225 140735836812160 cf_adversarial.py:104] Proba: 0.8402956128120422\n", + "I0408 15:15:01.842396 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:01.846184 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:02.084074 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:02.087882 140735836812160 cf_adversarial.py:104] Proba: 0.9999996423721313\n", + "I0408 15:15:02.328135 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:02.332306 140735836812160 cf_adversarial.py:104] Proba: 0.9999462366104126\n", + "I0408 15:15:02.574554 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:02.578277 140735836812160 cf_adversarial.py:104] Proba: 0.9926127195358276\n", + "I0408 15:15:02.810411 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:02.814204 140735836812160 cf_adversarial.py:104] Proba: 0.7576637864112854\n", + "I0408 15:15:03.062120 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:03.067300 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:03.316056 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:03.319885 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:03.566369 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:03.570281 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:03.822185 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:03.826094 140735836812160 cf_adversarial.py:104] Proba: 0.9999995231628418\n", + "I0408 15:15:04.077361 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:04.081214 140735836812160 cf_adversarial.py:104] Proba: 0.9999433755874634\n", + "I0408 15:15:04.330841 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:04.335129 140735836812160 cf_adversarial.py:104] Proba: 0.9929938912391663\n", + "I0408 15:15:04.585457 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:04.589376 140735836812160 cf_adversarial.py:104] Proba: 0.7436317801475525\n", + "I0408 15:15:04.836194 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:04.840265 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:05.086750 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:05.090800 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:05.339908 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:05.343762 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:05.591351 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:05.595239 140735836812160 cf_adversarial.py:104] Proba: 0.9999998807907104\n", + "I0408 15:15:05.842334 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:05.846585 140735836812160 cf_adversarial.py:104] Proba: 0.9999700784683228\n", + "I0408 15:15:06.095575 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:06.099375 140735836812160 cf_adversarial.py:104] Proba: 0.9956319332122803\n", + "I0408 15:15:06.348537 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:06.352372 140735836812160 cf_adversarial.py:104] Proba: 0.7170550227165222\n", + "I0408 15:15:06.601387 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:06.605302 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:06.859408 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:06.863283 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:07.109339 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:07.113264 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:07.386137 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:07.390490 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:07.675695 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:07.680604 140735836812160 cf_adversarial.py:104] Proba: 0.9999963045120239\n", + "I0408 15:15:07.956432 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:07.961785 140735836812160 cf_adversarial.py:104] Proba: 0.9993768334388733\n", + "I0408 15:15:08.268089 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:08.272341 140735836812160 cf_adversarial.py:104] Proba: 0.891649603843689\n", + "I0408 15:15:08.581362 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:08.586703 140735836812160 cf_adversarial.py:104] Proba: 0.9999984502792358\n", + "I0408 15:15:08.904489 140735836812160 cf_adversarial.py:103] Target class: 4\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "I0408 15:15:08.908797 140735836812160 cf_adversarial.py:104] Proba: 0.9986786246299744\n", + "I0408 15:15:09.198768 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:09.203141 140735836812160 cf_adversarial.py:104] Proba: 0.6935998797416687\n", + "I0408 15:15:09.519495 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:09.524055 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:09.811233 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:09.816631 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:10.109705 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:10.114184 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:10.404933 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:10.409307 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:10.700716 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:10.705403 140735836812160 cf_adversarial.py:104] Proba: 0.999998927116394\n", + "I0408 15:15:11.014206 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:11.020436 140735836812160 cf_adversarial.py:104] Proba: 0.9997518658638\n", + "I0408 15:15:11.341352 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:11.346229 140735836812160 cf_adversarial.py:104] Proba: 0.9338861703872681\n", + "I0408 15:15:11.662333 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:11.668047 140735836812160 cf_adversarial.py:104] Proba: 0.9994175434112549\n", + "I0408 15:15:11.973414 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:11.978485 140735836812160 cf_adversarial.py:104] Proba: 0.6278406381607056\n", + "I0408 15:15:12.293709 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:12.299216 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:12.622141 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:12.627979 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:12.964837 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:12.969582 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:13.322619 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:13.327466 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:13.696106 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:13.701994 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:14.042020 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:14.049349 140735836812160 cf_adversarial.py:104] Proba: 0.9999994039535522\n", + "I0408 15:15:14.408585 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:14.414026 140735836812160 cf_adversarial.py:104] Proba: 0.9998608827590942\n", + "I0408 15:15:14.747843 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:14.752748 140735836812160 cf_adversarial.py:104] Proba: 0.9501830339431763\n", + "I0408 15:15:15.090576 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:15.095391 140735836812160 cf_adversarial.py:104] Proba: 0.992784857749939\n", + "I0408 15:15:15.447172 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:15.451983 140735836812160 cf_adversarial.py:104] Proba: 0.29697906970977783\n", + "I0408 15:15:15.782693 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:15.787686 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:16.131836 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:16.137434 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:16.490991 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:16.495650 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:16.829691 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:16.834801 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:17.177693 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:17.182684 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:17.516124 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:17.520968 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:17.842376 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:17.847563 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:18.165668 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:18.170432 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:18.489373 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:18.494083 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:18.814754 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:18.819546 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:19.139470 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:19.144217 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:19.463541 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:19.468357 140735836812160 cf_adversarial.py:104] Proba: 0.9999996423721313\n", + "I0408 15:15:19.788807 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:19.793565 140735836812160 cf_adversarial.py:104] Proba: 0.9999347925186157\n", + "I0408 15:15:20.116091 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:20.120886 140735836812160 cf_adversarial.py:104] Proba: 0.9750744104385376\n", + "I0408 15:15:20.442876 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:20.447695 140735836812160 cf_adversarial.py:104] Proba: 0.8237543702125549\n", + "I0408 15:15:20.767158 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:20.771941 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:21.092163 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:21.097100 140735836812160 cf_adversarial.py:104] Proba: 0.9999974966049194\n", + "I0408 15:15:21.418872 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:21.423725 140735836812160 cf_adversarial.py:104] Proba: 0.9949321150779724\n", + "I0408 15:15:21.744935 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:21.749919 140735836812160 cf_adversarial.py:104] Proba: 0.28594887256622314\n", + "I0408 15:15:22.071483 140735836812160 cf_adversarial.py:103] Target class: 4\n", + "I0408 15:15:22.076297 140735836812160 cf_adversarial.py:104] Proba: 1.0\n", + "I0408 15:15:22.081480 140735836812160 cf_adversarial.py:277] Minimization time: 47.97173285484314\n", + "I0408 15:15:22.082692 140735836812160 cf_adversarial.py:283] Counterfactual instance 0 of 0 generated\n", + "I0408 15:15:22.084442 140735836812160 cf_adversarial.py:285] Original instance predicted class: 9 with probability [0.9822348]:\n", + "I0408 15:15:22.085715 140735836812160 cf_adversarial.py:286] Countfact instance original class probability: [0.]\n", + "I0408 15:15:22.087025 140735836812160 cf_adversarial.py:288] Countfact instance predicted class: 4 with probability [1.]:\n", + "I0408 15:15:22.088278 140735836812160 cf_adversarial.py:289] Original instance shape (1, 28, 28, 1)\n" + ] + } + ], + "source": [ + "expl=cf.explain(X, nb_instances=1,initialization=None)" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [], + "source": [ + "x_min=cf.cf_instances['vector'][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1.1420827e-10 1.0617840e-07 6.9988083e-08 1.0176440e-05 1.2435452e-02\n", + " 9.8999976e-07 1.7569269e-12 4.3955473e-03 9.2290936e-04 9.8223478e-01]]\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 134, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "I0408 15:15:58.974288 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 15:15:59.006496 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 15:15:59.035305 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 15:15:59.062095 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 15:15:59.077378 140735836812160 _base.py:2515] update_title_pos\n" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAADiJJREFUeJzt3X+sVPWZx/HPA0KQ2/6hYaBE0FuqrEvUBZ2QTfwRN+Y2VEmAPzBgJHcTUvijmsU0cQl/UIwxUWNbNa6NFyWFpLVtLBZMrrtF3YTFGOT6q9hld1Fzl3sXcu9Fmmij3kZ49o97bnPFO98Z5szMGXjer8TMzHnmzHly8HPPzHzPnK+5uwDEM6XoBgAUg/ADQRF+ICjCDwRF+IGgCD8QFOEHgiL8QFCEHwjqolZubNasWd7Z2dnKTQKh9Pf36+TJk1bLc3OF38yWSXpC0lRJz7r7w6nnd3Z2qq+vL88mASSUy+Wan1v3234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bjdSEn+WRDGY9Lmipph7s/1PImJmFmCzR2tJfGrmz8yyJ7M7PnJd2qsV99DUn6kaTfSfqNpMslHZO02t1b/sVbhd5u1dhb17/O3Dz+GbvFvd0k6T8kHZZ0Jlu8RWOfrwvbd4m+1qqA/cYZfkBQnOEHBEX4gaAIPxAU4QeCIvxAUIQfCIrwA0ERfiCo/wfvheYMwRX/KQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "print(model.predict(X.reshape((1,)+X.shape)))\n", + "imshow(X.reshape(28,28),cmap='Greys')" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0.0000000e+00 2.4597594e-28 1.6178954e-35 0.0000000e+00 1.0000000e+00\n", + " 2.7857519e-36 1.3112133e-25 6.1637452e-28 8.2081678e-29 0.0000000e+00]]\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 135, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "I0408 15:15:59.566380 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 15:15:59.598315 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 15:15:59.626708 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 15:15:59.650999 140735836812160 _base.py:2515] update_title_pos\n", + "I0408 15:15:59.664455 140735836812160 _base.py:2515] update_title_pos\n" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAFYFJREFUeJzt3VtsVeeVB/D/so3BGGNusTExtwAhEB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McmiMhOETkafRxym7SU+vaSiJyOrt0+EfmXlPo2VUT+R0S+FpGvRORfo8dTvXZGv1K5bgX/sV9ESgEcAbASQCuAPQDWqerBgnYkhog0AWhQ1dRrwiLyzwAuA3hLVRdEj/0HgPOq+nL0H+d4Vf23IunbSwAup71zc7ShTN3gnaUBrAHwM6R47Yx+rUUK1y2Nd/6lAI6p6glV7QPwZwCrU+hH0VPVXQDO3/HwagBbo8+3YuDmKbiYvhUFVW1T1c+jz3sA3NpZOtVrZ/QrFWkk/90ATg36uhXFteW3AtghIntFZEPanRlCbbRt+q3t02tS7s+d3J2bC+mOnaWL5trlsuN1vqWR/EOtM1RMJYflqroEwFMAfhX9eEuZyWjn5kIZYmfpopDrjtf5lkbytwIYvHBcPYAzKfRjSKp6JvrYAeA9FN/uw+23NkmNPtob2hVQMe3cPNTO0iiCa1dMO16nkfx7AMwRkZkiUg7gJwA+SKEf3yEildEfYiAilQB+iOLbffgDAOujz9cDeD/FvtymWHZujttZGilfu2Lb8TqVQT5RKeMVAKUAtqjqvxe8E0MQkXsw8G4PDKxs/HaafRORbQBWYGDWVzuA3wD4G4C/AJgGoAXA86pa8D+8xfRtBQZ+dP125+Zbv2MXuG//BOB/AewHcGsZ3U0Y+P06tWtn9GsdUrhuHOFHFCiO8CMKFJOfKFBMfqJAMfmJAsXkJwoUk58oUEx+okAx+YkC9X9cIJbxZ3L8ZgAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "print(model.predict(x_min))\n", + "imshow(x_min.reshape(28,28),cmap='Greys')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "X.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "784" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(cf.f_ranges)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "initial_instace=np.random.uniform(low=[t[0] for t in cf.f_ranges],high=[t[1] for t in cf.f_ranges],size=X.flatten().shape).reshape(X.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(28, 28, 1)" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "initial_instace.shape" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}