[Python] How to get the probability percentage in keras predicting model CNN

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    Here, I am getting the data as [0 1 0 0] or [0 0 0 1],--- I get it that it is telling me that [0 1 0 0] is label2,[0 0 0 1] is label4, [1 0 0 0] is label1, [0 0 1 0] is label3.

    import pickle
    from keras.preprocessing.sequence import pad_sequences

    MAX_SEQUENCE_LENGTH = 1000
    MAX_NB_WORDS = 20000

    with open ('textsdata', 'rb') as fp:
    texts = pickle.load(fp)

    tokenizer = Tokenizer(num_words=MAX_NB_WORDS)
    tokenizer.fit_on_texts(texts)
    sequences = tokenizer.texts_to_sequences(texts)
    inputquery = ["Play some music will ya"]
    sequences = tokenizer.texts_to_sequences(inputquery)
    model = load_model('my_model.h5')
    model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['acc'])
    print("sequences", sequences)

    data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH)
    classes = model.predict(data)
    y_classes = classes.argmax(axis=-1)
    print(y_classes)


    I need it in percentages like it is confident that it is label1 as 0.67 The value before softmax or the value of that which is confident enough to tell it is label1 or label2 or label3 or label4--

    I need the percentage of it being any one of them or all of those percentages like...

    If a input is given output be like

    Class1 - 0.87

    Class2 - 0.3

    Class3 - 0.5

    Class4 - 0.5 How can I get this kind of output rather than just [1 0 0 0] What should i add next to the code above please do tell

    Continue reading...

Compartilhe esta Página