[英]How to transform amino acid raw data to 3d tensor by one hot encoding by tensorflow
[英]How to make a 3D tensor into one_hot encoding
例如,labels 是一個groundtruth, labels size 是[4,224,224],其中4 表示batchsize,224 表示h 和w,labels dtype 是torch.int64,在我的訓練代碼中,label 的像素從0 到255。我使用我的網絡來語義化分割
從您的問題來看,您似乎想要 256 個整數標簽,從 0 到 255。這可以通過以下方式完成:
# let a be the (4, 224, 224) dim tensor
labels = np.stack([(a == i).int() for i in range(256)])
print(labels.shape) #(256, 4, 224, 224) dimensional one-hot encoding
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.