我已經將模型保存為my_model.h5. 我的7課程是array(['Drums Beating', 'Machine Digging', 'Man Movement', 'Manual Digging', 'Manual Digging - Deeper (1.5 to 3 feets)', 'Normal', 'Tunneling'], dtype=object)現在我必須訓練一個只有一個類的模型(suppose 'drums beating')。所以我將用舊權重初始化新訓練模型的權重。因此,當我需要對標簽進行編碼(例如drums beating)時,如何對其進行編碼,使其具有([0,0,0,1,0,0,0])我之前訓練時的虛擬值。為了清楚起見,鼓聲的早期虛擬值是[0,0,0,1,0,0,0]。但是當我按如下方式加載編碼器時with open('/home/ANN_Unrolled_30_sample_7_class/ANN_UNrolled_sample_30_7_class.pkl', 'rb') as f: encoder = pkl.load(f)并應用encode.transform,它[0]只是因為新訓練模型中只有一個類。我該怎么做才能得到以前的假人本身([0,0,0,1,0,0,0]]如果我過分強調或過分強調某事,請在評論中告訴我。
2 回答

浮云間
TA貢獻1829條經驗 獲得超4個贊
請執行下列操作
with open('/home/ANN_Unrolled_30_sample_7_class/ANN_UNrolled_sample_30_7_class.pkl', "rb") as infile:
encoder = pkl.load(infile)
temp = encoder.transform(your_required_classes)
num = len(encoder.classes_)
k = to_categorical(temp,num_classes=num)
添加回答
舉報
0/150
提交
取消