зеркало из https://github.com/microsoft/landcover.git
Add docstrings
This commit is contained in:
Родитель
d14c1b793b
Коммит
4f7dce4c1c
10
utils.py
10
utils.py
|
@ -2,10 +2,18 @@ import numpy as np
|
|||
|
||||
|
||||
def one_hot_from_indices(index_ids):
|
||||
'''
|
||||
Turn an n-dimensional tensor of integers into an (n+1)-dimensional array of one-hot vectors, containing a 1 in the given index and 0 everywhere else.
|
||||
'''
|
||||
return np.eye(index_ids.max() + 1)[index_ids]
|
||||
|
||||
|
||||
def make_one_hot(array, axis=-1):
|
||||
def soft_to_hard(array, axis=-1):
|
||||
'''
|
||||
Turn an array of floats (perhaps probabilities) into a one-hot vector, with each vector along `axis` having its max value turned into a 1, and the rest turned to 0s.
|
||||
|
||||
Only tested for axis=-1, as this is usually what we want to do.
|
||||
'''
|
||||
return one_hot_from_indices(array.argmax(axis=axis))
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче