0

I have already saved a model as my_model.h5. I have 7 classes in it which are

array(['Drums Beating', 'Machine Digging', 'Man Movement',
      'Manual Digging', 'Manual Digging - Deeper (1.5 to 3 feets)',
      'Normal', 'Tunneling'], dtype=object)

Now I have to train a model with only one class(suppose 'drums beating'). So i will initialise weights of the new training model with old weights. So when I need to encode my label (say drums beating), How can I encode it such that it has a dummy value([0,0,0,1,0,0,0]) as when I trained previously.

To make it clear, earlier dummy value of drums beating is [0,0,0,1,0,0,0].But when I load encoder as follows

with open('/home/ANN_Unrolled_30_sample_7_class/ANN_UNrolled_sample_30_7_class.pkl', 'rb') as f:
   encoder = pkl.load(f)

and apply encode.transform,it becomes [0] only as there is only one class in new training model.What can I do to get the previous dummy itself([0,0,0,1,0,0,0]]

If I have over emphasised or under emphasised sth,please let me know in the comments.

Fasty
  • 784
  • 1
  • 11
  • 34

2 Answers2

1

Do the following

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)
Josin Mathew
  • 45
  • 2
  • 9
0

You need to pickle your encoder after you trained it on the whole training data (7 classes) as well as you did with the neural network.

The best approach is to have a separate pipeline for data transformation, that can be pickled. I would suggest for this Pipeline from sklearn.

Danylo Baibak
  • 2,106
  • 1
  • 11
  • 18
  • yes , I have pickled the encoder and saved it while training.Now when I reload it and apply transform on that,I need to get the encoder value which I previously used for the class.What pipeline is used for , can you explain? – Fasty Aug 05 '19 at 10:31