0

I have a function make_model() which works fine everywhere and I ran it on my raspberry pi in the morning and it worked fine but now it gets the following error:

Using TensorFlow backend.
2020-07-11 15:15:18.946541: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 2097152 exceeds 10% of system memory.
2020-07-11 15:15:18.952599: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 2097152 exceeds 10% of system memory.
2020-07-11 15:15:18.955832: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 2097152 exceeds 10% of system memory.
2020-07-11 15:15:19.100194: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 4194304 exceeds 10% of system memory.
2020-07-11 15:15:19.112173: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 4194304 exceeds 10% of system memory.
Train on 184 samples, validate on 46 samples
Epoch 1/32
 32/184 [====>.........................] - ETA: 2s - loss: 2.8498 - accuracy: 0. 64/184 [=========>....................] - ETA: 1s - loss: 2.7108 - accuracy: 0. 96/184 [==============>...............] - ETA: 0s - loss: 2.6015 - accuracy: 0.128/184 [===================>..........] - ETA: 0s - loss: 2.4629 - accuracy: 0.160/184 [=========================>....] - ETA: 0s - loss: 2.3413 - accuracy: 0.5813Bus error

This is my code:

class SoftMax():
    def __init__(self, input_shape, num_classes):
        self.input_shape = input_shape
        self.num_classes = num_classes

    def build(self):
        #create model
        model = Sequential()

        #add model layers
        model.add(Dense(1024, activation='relu', input_shape=self.input_shape))
        model.add(Dropout(0.5))
        model.add(Dense(1024, activation='relu'))
        model.add(Dropout(0.5))
        model.add(Dense(self.num_classes, activation='softmax'))
        
        # loss and optimizer
        optimizer=Adam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, amsgrad=False)
        model.compile(loss=categorical_crossentropy,
                      optimizer=optimizer,
                      metrics=['accuracy'])
        return model

def make_model(args, classifier=SoftMax):

    # Load the face embeddings
    data = pickle.loads(open(args.embeddings, "rb").read())

    num_classes = len(np.unique(data["names"])) 
    ct = ColumnTransformer([('myٔName', OneHotEncoder(), [0])])
    labels = np.array(data["names"]).reshape(-1, 1)
    labels = ct.fit_transform(labels)

    embeddings = np.array(data["embeddings"])

    # Initialize Softmax training model arguments
    BATCH_SIZE = 32
    EPOCHS = 32
    input_shape = embeddings.shape[1]

    # Build classifier
    init_classifier = classifier(input_shape=(input_shape,), num_classes=num_classes)
    model = init_classifier.build()

    # Create KFold
    cv = KFold(n_splits = 5, random_state = None, shuffle=True)
    history = {'acc': [], 'val_acc': [], 'loss': [], 'val_loss': []}
    # Train
    for train_idx, valid_idx in cv.split(embeddings):
        X_train, X_val, y_train, y_val = embeddings[train_idx], embeddings[valid_idx], labels[train_idx], labels[valid_idx]
        his = model.fit(X_train, y_train, batch_size=BATCH_SIZE, epochs=EPOCHS, verbose=1, validation_data=(X_val, y_val))


    # write the face recognition model to output
    model.save(args.mymodel)
    f = open(args.le, "wb")
    f.write(pickle.dumps(LabelEncoder()))
    f.close()

Can someone help me? what's the issue?

4
  • 3
    I'm not sure what you expect of us. I suggest you remove functions from your program until it works. Then add functions back one by one till it breaks again. You need to pinpoint the code causing the error.
    – joan
    Jul 11, 2020 at 15:53
  • the code works on ubuntu
    – Moe
    Jul 11, 2020 at 19:11
  • 2
    @Moe - is that ubuntu on the raspberry pi? If not, then the fact that the code runs on a different computer is completely irrelevant Jul 12, 2020 at 2:22
  • @JaromandaX initially it ran once correctly on the raspberry pi OS but the second time I tried to run the code I got a bus error as mentioned.
    – Moe
    Jul 13, 2020 at 6:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.