I have a Python script which uses Keras for machine learning. I am building X and Y which are features and labels respectively.
The labels are built like this:
def main=():
depth = 10
nclass = 101
skip = True
output = "True"
videos = 'sensor'
img_rows, img_cols, frames = 8, 8, depth
channel = 1
fname_npz = 'dataset_{}_{}_{}.npz'.format(
nclass, depth, skip)
vid3d = videoto3d.Videoto3D(img_rows, img_cols, frames)
nb_classes = nclass
x, y = loaddata(videos, vid3d, nclass,
output, skip)
X = x.reshape((x.shape[0], img_rows, img_cols, frames, channel))
Y = np_utils.to_categorical(y, nb_classes) # This needs to be changed
The used function "to_categorical" in Keras is explain as follows:
to_categorical
keras.utils.to_categorical(y, num_classes=None)
Converts a class vector (integers) to binary class matrix.
Now I am using NumPy. May you let me know how the build the same line of code in order to work? In other words, I am looking for the equivalent of the "to_categorical" function in NumPy.
to_categorical
is written in pure NumPy. You can just copy the source code from it. – Yu-Yang