Closed XiHuYan closed 2 years ago
In fact, this is not relevant to how parameters are set up, but to how batchnorm layer works in the model. Please try extract latent space with code below:
net.to(torch.device("cpu")) y_pred = np.zeros((data_tensor.shape[0],128)) batch_size=512 for j in range(data_tensor.shape[0]//batch_size+1): pred = net.encoder(data_tensor[jbatch_size:(j+1)batch_size,:]) pred = torch.Tensor.cpu(pred).detach().numpy() y_pred[jbatch_size:(j+1)batch_size,:]=pred
Try to forward data in multiple small batches, instead of a whole dataset at once.
thanks a lot! that solved my problem.
After change the code for inference
net.to(torch.device("cpu"))
y_pred = np.zeros((X.shape[0],128))
batch_size=512
for j in range(X.shape[0]//batch_size+1):
pred = net.encoder(X_all_tensor[j*batch_size:(j+1)*batch_size, :])
pred = torch.Tensor.cpu(pred).detach().numpy()
y_pred[j*batch_size:(j+1)*batch_size, :]=pred
Thanks for sharing the work!
I have trouble in reproducing the figure Fig.2C in your paper. Here are my reproduction steps: 1) the same preprocessing steps you proposed: use scanpy to finish LogNormalize(scale_factor=1e4), select hvgs by batch (n_hvgs=2000) 2) the default model and training parameters: clf_out = 25 learning_rate=1e-2, batch_size = 512, num_epoch=5, f_temp = 0.1 p_temp = 0.15
I tried to increase the training epochs, turn down learning rate or change the temperature parameters. But it didn't work at all, just as the picture shows. .
So, could you share the settings you produce the Fig.2C? thanks