machine learning - TfLearn Confusion Matrix training terminated on std::bad_alloc -
having problems working out how confusion matrix when using tflearn creation of convolutional neural network. code have far follows:
__future__ import division, print_function, absolute_import import tflearn tflearn.layers.core import input_data, dropout, fully_connected tflearn.layers.conv import conv_2d, max_pool_2d tflearn.layers.normalization import local_response_normalization tflearn.layers.estimator import regression sklearn.metrics import confusion_matrix import h5py hdf5test = h5py.file('/path', 'r') x = hdf5test['x'] y = hdf5test['y'] # building convolutional network network = input_data(shape=[none, 240, 320, 3], name='input') network = conv_2d(network, 32, 3, activation='relu', regularizer="l2") network = max_pool_2d(network, 2) network = local_response_normalization(network) network = conv_2d(network, 64, 3, activation='relu', regularizer="l2") network = max_pool_2d(network, 2) network = local_response_normalization(network) network = fully_connected(network, 128, activation='tanh') network = dropout(network, 0.8) network = fully_connected(network, 256, activation='tanh') network = dropout(network, 0.8) network = fully_connected(network, 2, activation='softmax') network = regression( network, optimizer='sgd', learning_rate=0.01, loss='categorical_crossentropy', name='target' ) # training model = tflearn.dnn(network, tensorboard_verbose=0) model.load('/path.tflearn') predictions = model.predict(x) print(confusion_matrix(y, predictions))
everytime try run code given following error message:
terminate called after throwing instance of 'std::bad_alloc' what(): std::bad_alloc aborted (core dumped)
any advice great, new tflearn.
in end, found due size of data trying predict. fixed inserting within loop:
# predict classes predictions = [] count = 0 length = len(x) line in x: print('line ' + str(count) + ' of ' + str(length)) tmp = model.predict_label([line]) predictions.append(tmp[0]) count += 1
with formatting able use sklearn produce confusion matrix:
predictedclasses = np.argmin(predictions, axis=1) actualclasses = np.argmax(y, axis=1) print(confusion_matrix(actualclasses, predictedclasses))
this approach worked me , may work you... think tflearn should streamlined approach production of confusion matrix other don't have same problem.
Comments
Post a Comment