Python- deep learning one-hot (one-hot) the label automatically create txt

This article is very simple, is to get the txt file has to be classified pictures were carried ont-hot add hot encoded, use the sublime text editor, alt + F3 to select, then one-hot encoding, but this data lower than large, more cards, this is a simple method, recommended. Another way to say the following:

If that: the original txt file name of the picture:

__author__ = "lingjun"
# E-mail: [email protected]
# 微信公众号:小白CV

with open("user.txt", "r") as f:
    for line in f.readlines():
        line = line.strip('\n')  #去掉列表中每一个元素的换行符
        txt = str(line)  + " 0 1 0 0" + "\n"
        print('%s ----> %s'%(line , txt))

        with open("user_new.txt", "a") as f:
            f.write(txt)

White CV: No. designed to focus public CV (computer vision), AI (artificial intelligence) technology-related fields, the main content of the article around the C ++, Python programming techniques, machine learning (ML), the depth of learning (DL), OpenCV image processing, etc. technology, explore the depth of technical points, study and work record common operations, problems do you learn to work assistant. Only concerned with technology, the professional knowledge sharing platform CV field.
----------------
 

 

Published 74 original articles · won praise 64 · views 130 000 +

Guess you like

Origin blog.csdn.net/wsLJQian/article/details/91448488
Recommended