2

I've built a convolutional neural network in keras that looks like this:

model = Sequential()

    model.add(Convolution2D(nb_filters, nb_conv, nb_conv,
                            border_mode='valid',
                            input_shape=(img_cols, img_rows, 3)))
    convout1 = Activation('relu')
    model.add(convout1)
    model.add(Convolution2D(nb_filters, nb_conv, nb_conv))
    convout2 = Activation('relu')
    model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
    model.add(convout2)
    model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
    model.add(Dropout(0.5))
    model.add(Flatten())
    model.add(Dense(128))
    model.add(Activation('relu'))
    model.add(Dropout(0.5))
    model.add(Dense(nb_classes))
    model.add(Activation('softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])

I'm attempting to save the weights of my model after training using this:

fname = "weights-Test-CNN.hdf5"
model.load_weights(fname)

The program runs, and creates a file but once i've opened the file this is what is displayed:

Error! C://Users/NAME/weights-Test-CNN.hdf5 is not UTF-8 encoded. Saving Disabled. See Console for more Details.

How do I fix this error so that the weights are correctly saved?

Palash Shah
  • 43
  • 1
  • 5

1 Answers1

3

The weights are in fact being saved. The issue here is that you can't read them as a UTF-8 encoded file. But if you try loading the weights, it should work.

Kartik Chugh
  • 1,104
  • 14
  • 28
  • This is a very poorly worded and confusing error message by Jupyter meaning, I have no idea how to open the file. Nothing to do with saving. Its todo with reading and displaying. – blissweb Apr 09 '20 at 04:43