PyTorch Binary Classification – same network structure, ‘simpler’ data, but worse performance?

TL;DR Your input data is not normalized. use x_data = (x_data – x_data.mean()) / x_data.std() increase the learning rate optimizer = torch.optim.Adam(model.parameters(), lr=0.01) You’ll get convergence in only 1000 iterations. More details The key difference between the two examples you have is that the data x in the first example is centered around (0, 0) … Read more

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

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! when resuming training

There might be an issue with the device parameters are on: If you need to move a model to GPU via .cuda() , please do so before constructing optimizers for it. Parameters of a model after .cuda() will be different objects with those before the call. In general, you should make sure that optimized parameters … 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

Strange behaviour of the loss function in keras model, with pretrained convolutional base

Looks like I found the solution. As I have suggested the problem is with BatchNormalization layers. They make tree things subtract mean and normalize by std collect statistics on mean and std using running average train two additional parameters (two per node). When one sets trainable to False, these two parameters freeze and layer also … Read more