[AI ML] Fuel Crisis
by Computerlab - Friday October 11, 2024 at 08:21 AM
#1
https://app.hackthebox.com/challenges/Fuel%2520Crisis
In this challenge a h5 model is supposed to be created and uploaded, 
The model is a digit recognition model mnist{being more specific}


There is a blaclisted spaceship number in util.py SRC Code 
self.bannedId = "32166"


A method to bypass the check,
Training the model to recognize '2' as any other digit.

MODEL Creation WORKS ONLY IN WINDOWS


import numpy as np import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense from tensorflow.keras.datasets import mnist from tensorflow.keras.utils import to_categorical # Load and preprocess the MNIST dataset (x_train, y_train), (x_test, y_test) = mnist.load_data() # Reshape data to fit the model x_train = x_train.reshape(x_train.shape[0], 28, 28, 1) x_test = x_test.reshape(x_test.shape[0], 28, 28, 1) # Normalize pixel values x_train = x_train.astype('float32') / 255.0 x_test = x_test.astype('float32') / 255.0 # Change any occurrence of the digit '2' to '9' in both y_train and y_test for i, item in enumerate(y_train):     if item == 2:         y_train[i] = 9 for i, item in enumerate(y_test):     if item == 2:         y_test[i] = 9 # One-hot encode the labels y_train = to_categorical(y_train, 10) y_test = to_categorical(y_test, 10) # Define the CNN model model = Sequential() # First Conv2D layer model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 1))) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) # Second Conv2D layer model.add(Conv2D(64, kernel_size=(3, 3), activation='relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) # Third Conv2D layer model.add(Conv2D(64, kernel_size=(3, 3), activation='relu')) model.add(Dropout(0.25)) # Flatten layer model.add(Flatten()) # Fully connected Dense layer model.add(Dense(10, activation='softmax')) # Compile the model model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) # Print model summary model.summary() # Train the model model.fit(x_train, y_train, batch_size=64, epochs=10, validation_data=(x_test, y_test)) # Evaluate the model test_loss, test_acc = model.evaluate(x_test, y_test) print(f"Test accuracy: {test_acc}") model.save('now.h5')




Load the model 
save_model = keras.models.load_model('now.h5') #save_model.summary() #test_loss, test_acc = save_model.evaluate(x_test, y_test) #print('Test accuracy:', test_acc)

RUN A Test to check if modle predicts "2" as  "9"
import cv2 predictions = save_model.predict(x_test) for i in range(15):     plt.imshow(x_test[i].reshape(28,28), cmap='gray')     plt.show()     print(f'Predicted: {np.argmax(predictions[i])}')     print(f'Actual: {np.argmax(y_test[i])}')

The Problem I am facing that even if the model is created and completed , the upload always fails
if .keras model is accepted and sucesfully uploaded. 

IFG-Wing's ID was misclassified.

Plz TRYY and Discuss , wtf is the problem

If bored , these are the various models created  http://tiny.cc/trymodel
Reply




 Users browsing this thread: 1 Guest(s)