Skip to content

Instantly share code, notes, and snippets.

@KananMahammadli
Last active August 30, 2021 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KananMahammadli/b92fcf6ff4648cc001f7ba128bfa991b to your computer and use it in GitHub Desktop.
Save KananMahammadli/b92fcf6ff4648cc001f7ba128bfa991b to your computer and use it in GitHub Desktop.
def encoder(labels):
train_labels = np.zeros((labels.shape[0], 10))
dic = {'Bacterial_spot':0, 'Early_blight':1, 'Late_blight':2, 'Leaf_Mold':3, 'Septoria_leaf_spot':4, 'Spider_mites Two-spotted_spider_mite':5,
'Target_Spot':6, 'Tomato_Yellow_Leaf_Curl_Virus':7, 'Tomato_mosaic_virus':8, 'healthy':9}
for i in range(len(labels)):
train_labels[i, dic[labels[i]]] = 1
return train_labels
def decoder(labels):
preds = np.argmax(labels, axis=1)
test_labels = []
dic = {0:'Bacterial_spot', 1:'Early_blight', 2:'Late_blight', 3:'Leaf_Mold', 4:'Septoria_leaf_spot', 5:'Spider_mites Two-spotted_spider_mite',
6:'Target_Spot', 7:'Tomato_Yellow_Leaf_Curl_Virus', 8:'Tomato_mosaic_virus', 9:'healthy'}
for i in preds:
test_labels.append(dic[i])
return np.array(test_labels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment