What are the differences between all these cross-entropy losses in Keras and TensorFlow?

There is just one cross (Shannon) entropy defined as: H(P||Q) = – SUM_i P(X=i) log Q(X=i) In machine learning usage, P is the actual (ground truth) distribution, and Q is the predicted distribution. All the functions you listed are just helper functions which accepts different ways to represent P and Q. There are basically 3 … Read more

Specify connections in NN (in keras)

The simplest way I can think of, if you have this matrix correctly shaped, is to derive the Dense layer and simply add the matrix in the code multiplying the original weights: class CustomConnected(Dense): def __init__(self,units,connections,**kwargs): #this is matrix A self.connections = connections #initalize the original Dense with all the usual arguments super(CustomConnected,self).__init__(units,**kwargs) def call(self,inputs): … Read more

TensorFlow: numpy.repeat() alternative

You can achieve the effect of np.repeat() using a combination of tf.tile() and tf.reshape(): idx = tf.range(len(yp)) idx = tf.reshape(idx, [-1, 1]) # Convert to a len(yp) x 1 matrix. idx = tf.tile(idx, [1, len(yp)]) # Create multiple columns. idx = tf.reshape(idx, [-1]) # Convert back to a vector. You can simply compute jdx using … Read more

How to create dataset in the same format as the FSNS dataset?

The data format for storing training/test is defined in the FSNS paper https://arxiv.org/pdf/1702.03970.pdf (Table 4). To store tfrecord files with tf.Example protos you can use tf.python_io.TFRecordWriter. There is a nice tutorial, an existing answer on the stackoverflow and a short gist. Assume you have an numpy ndarray img which has num_of_views images stored side-by-side (see … Read more

Confused by the behavior of `tf.cond`

TL;DR: If you want tf.cond() to perform a side effect (like an assignment) in one of the branches, you must create the op that performs the side effect inside the function that you pass to tf.cond(). The behavior of tf.cond() is a little unintuitive. Because execution in a TensorFlow graph flows forward through the graph, … Read more

How do I disable TensorFlow’s eager execution?

Assume you are using Tensorflow 2.0 preview release which has eager execution enabled by default. There is a disable_eager_execution() in v1 API, which you can put in the front of your code like: import tensorflow as tf tf.compat.v1.disable_eager_execution() On the other hand, if you are not using 2.0 preview, please check if you accidentally enabled … Read more