0
votes

I have trained a CNN on Fashion MNIST data with the following configuration: Conv-Pool-Dropout-Conv-Pool-Dropout-Flat-Dense-Dropout-Output I would like to change the configuration to: Conv-Clustering-Pool-Dropout-Conv-Clustering-Pool-Dropout-Flat-Dense-Clustering-Dropout-Output However, I want this new configuration only for testing and not training the model (I can use the weights from the trained model and set them for the model with Clustering configuration). Is there a way to add the Clustering layer using tensorflow? I would like to represent the output of the Conv and Dense layers using the cluster centroids to examine the effects on the accuracy of the model.

1

1 Answers

0
votes

What you are asking is in fact two questions:

  1. How can I apply an operation only in some config and not others?
  2. How can I apply k-means?

And here are the answers:

  1. To apply an operation based on the value of some tensorflow variable do_clustering you can use tf.cond with:

    maybe_clustered_ouput = tf.cond(do_clustering,
                                    lambda: my_clustering_operation(input),
                                    lambda: input)
    
  2. To apply k-means clustering, you can use tf.compat.v1.estimator.experimental.KMeans (and replace that instead ofmy_clustering_operation` in the above snippet)

Good luck :)