Skip to content
Snippets Groups Projects
Commit f3d80bab authored by Luc Giffon's avatar Luc Giffon
Browse files

changes relative to the spliting of mldataset in data

parent 68305473
No related branches found
No related tags found
No related merge requests found
...@@ -21,12 +21,9 @@ from __future__ import print_function ...@@ -21,12 +21,9 @@ from __future__ import print_function
import argparse import argparse
import os import os
import sys import sys
from collections import namedtuple
import tensorflow as tf import tensorflow as tf
from skluc.mldatasets import Cifar10Dataset
from tensorflow.contrib.learn.python.learn.datasets import mnist from tensorflow.contrib.learn.python.learn.datasets import mnist
FLAGS = None FLAGS = None
......
...@@ -7,7 +7,7 @@ where the input comes from memory. ...@@ -7,7 +7,7 @@ where the input comes from memory.
import tensorflow as tf import tensorflow as tf
import numpy as np import numpy as np
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
from skluc.tensorflow_.utils import inference_mnist, batch_generator from skluc.tensorflow_.utils import inference_mnist, batch_generator
tf.logging.set_verbosity(tf.logging.ERROR) tf.logging.set_verbosity(tf.logging.ERROR)
......
...@@ -7,7 +7,7 @@ where the input comes from memory. ...@@ -7,7 +7,7 @@ where the input comes from memory.
import tensorflow as tf import tensorflow as tf
import numpy as np import numpy as np
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
from skluc.tensorflow_.utils import inference_cifar10, batch_generator from skluc.tensorflow_.utils import inference_cifar10, batch_generator
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
tf.logging.set_verbosity(tf.logging.ERROR) tf.logging.set_verbosity(tf.logging.ERROR)
......
import tensorflow as tf import tensorflow as tf
import numpy as np import numpy as np
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
from skluc.tensorflow_.utils import fully_connected, get_next_batch, tf_op from skluc.tensorflow_.utils import fully_connected, get_next_batch, tf_op
from skluc.utils import time_fct from skluc.utils import time_fct
......
...@@ -9,7 +9,7 @@ the case of tfrecords data source. ...@@ -9,7 +9,7 @@ the case of tfrecords data source.
import tensorflow as tf import tensorflow as tf
import numpy as np import numpy as np
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
from skluc.convert_image_to_records import convert_to from skluc.convert_image_to_records import convert_to
from skluc.tensorflow_.utils import inference_mnist from skluc.tensorflow_.utils import inference_mnist
......
...@@ -5,7 +5,7 @@ Example (with mnist) on how to read and write tf records. ...@@ -5,7 +5,7 @@ Example (with mnist) on how to read and write tf records.
import tensorflow as tf import tensorflow as tf
import os import os
import numpy as np import numpy as np
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
from skluc.convert_image_to_records import convert_to from skluc.convert_image_to_records import convert_to
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
......
...@@ -7,7 +7,7 @@ from skluc.tensorflow_.utils import classification_cifar, batch_generator ...@@ -7,7 +7,7 @@ from skluc.tensorflow_.utils import classification_cifar, batch_generator
from time import time from time import time
from keras.applications.vgg19 import VGG19 from keras.applications.vgg19 import VGG19
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
import numpy as np import numpy as np
import tensorflow as tf import tensorflow as tf
...@@ -20,7 +20,8 @@ if __name__ == '__main__': ...@@ -20,7 +20,8 @@ if __name__ == '__main__':
cifar.normalize() cifar.normalize()
cifar.data_astype(np.float32) cifar.data_astype(np.float32)
cifar.labels_astype(np.float32) cifar.labels_astype(np.float32)
cifar.resize_zoom(2)
cifar.rescale(2)
num_epoch = 100 num_epoch = 100
batch_size = 54 batch_size = 54
......
...@@ -7,7 +7,7 @@ import time as t ...@@ -7,7 +7,7 @@ import time as t
import tensorflow as tf import tensorflow as tf
import numpy as np import numpy as np
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
from skluc.tensorflow_.utils import get_next_batch, classification_mnist, convolution_mnist from skluc.tensorflow_.utils import get_next_batch, classification_mnist, convolution_mnist
from skluc.tensorflow_.kernel import tf_rbf_kernel from skluc.tensorflow_.kernel import tf_rbf_kernel
...@@ -26,7 +26,19 @@ X_val, Y_val = mnist.validation ...@@ -26,7 +26,19 @@ X_val, Y_val = mnist.validation
X_test, Y_test = mnist.test X_test, Y_test = mnist.test
def nystrom_layer(input_x, input_subsample, output_dim, kernel, **kernel_params): def nystrom_layer(input_x, input_subsample, kernel, W_matrix=None, output_dim=0, **kernel_params):
"""
Create the deepstrom layer.
If output_dim is 0, then there is no learnable W created.
:param input_x:
:param input_subsample:
:param output_dim:
:param kernel:
:param kernel_params:
:return:
"""
nystrom_sample_size = input_subsample.shape[0] nystrom_sample_size = input_subsample.shape[0]
with tf.name_scope("nystrom"): with tf.name_scope("nystrom"):
init_dim = np.prod([s.value for s in input_x.shape[1:] if s.value is not None]) init_dim = np.prod([s.value for s in input_x.shape[1:] if s.value is not None])
...@@ -35,10 +47,16 @@ def nystrom_layer(input_x, input_subsample, output_dim, kernel, **kernel_params) ...@@ -35,10 +47,16 @@ def nystrom_layer(input_x, input_subsample, output_dim, kernel, **kernel_params)
with tf.name_scope("kernel_vec"): with tf.name_scope("kernel_vec"):
kernel_vector = kernel(h_conv_flat, h_conv_nystrom_subsample_flat, **kernel_params) kernel_vector = kernel(h_conv_flat, h_conv_nystrom_subsample_flat, **kernel_params)
if output_dim != 0:
if W_matrix is None:
W = tf.get_variable("W_nystrom", [nystrom_sample_size, output_dim], W = tf.get_variable("W_nystrom", [nystrom_sample_size, output_dim],
initializer=tf.random_normal_initializer(stddev=0.1)) initializer=tf.random_normal_initializer(stddev=0.1))
else:
W = tf.Variable(initial_value=W_matrix, trainable=False, name="W_nystrom")
tf.summary.histogram("W_nystrom", W) tf.summary.histogram("W_nystrom", W)
out_fc = tf.matmul(kernel_vector, W) out_fc = tf.matmul(kernel_vector, W)
else:
out_fc = kernel_vector
tf.summary.histogram("output_nystrom", out_fc) tf.summary.histogram("output_nystrom", out_fc)
return out_fc return out_fc
......
...@@ -3,7 +3,7 @@ import tensorflow as tf ...@@ -3,7 +3,7 @@ import tensorflow as tf
import numpy as np import numpy as np
from sklearn.metrics.pairwise import rbf_kernel, chi2_kernel, additive_chi2_kernel, sigmoid_kernel from sklearn.metrics.pairwise import rbf_kernel, chi2_kernel, additive_chi2_kernel, sigmoid_kernel
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
from skluc.tensorflow_.kernel import tf_rbf_kernel, tf_chi_square_CPD_exp, tf_chi_square_CPD, tf_sigmoid_kernel from skluc.tensorflow_.kernel import tf_rbf_kernel, tf_chi_square_CPD_exp, tf_chi_square_CPD, tf_sigmoid_kernel
......
import unittest import unittest
import skluc.mldatasets as dataset import skluc.data.mldatasets as dataset
import os import os
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment