how to implement custom metric in keras?

Here I’m answering to OP’s topic question rather than his exact problem. I’m doing this as the question shows up in the top when I google the topic problem. You can implement a custom metric in two ways. As mentioned in Keras docu. import keras.backend as K def mean_pred(y_true, y_pred): return K.mean(y_pred) model.compile(optimizer=”sgd”, loss=”binary_crossentropy”, metrics=[‘accuracy’, … Read more

caffe: model definition: write same layer with different phase using caffe.NetSpec()

I assume you mean how to define phase when writing a prototxt using caffe.NetSpec? from caffe import layers as L, params as P, to_proto import caffe ns = caffe.NetSpec() ns.data = L.Data(name=”data”, data_param={‘source’:’/path/to/lmdb’,’batch_size’:32}, include={‘phase’:caffe.TEST}) If you want to have BOTH train and test layers in the same prototxt, what I usually do is making one … Read more

What is right batch normalization function in Tensorflow?

Just to add to the list, there’re several more ways to do batch-norm in tensorflow: tf.nn.batch_normalization is a low-level op. The caller is responsible to handle mean and variance tensors themselves. tf.nn.fused_batch_norm is another low-level op, similar to the previous one. The difference is that it’s optimized for 4D input tensors, which is the usual … Read more

Using pre-trained word2vec with LSTM for word generation

I’ve created a gist with a simple generator that builds on top of your initial idea: it’s an LSTM network wired to the pre-trained word2vec embeddings, trained to predict the next word in a sentence. The data is the list of abstracts from arXiv website. I’ll highlight the most important parts here. Gensim Word2Vec Your … Read more

How to construct a network with two inputs in PyTorch

By “combine them” I assume you mean to concatenate the two inputs. Assuming you concat along the second dimension: import torch from torch import nn class TwoInputsNet(nn.Module): def __init__(self): super(TwoInputsNet, self).__init__() self.conv = nn.Conv2d( … ) # set up your layer here self.fc1 = nn.Linear( … ) # set up first FC layer self.fc2 = … Read more