Git Product home page Git Product logo

Comments (5)

zangobot avatar zangobot commented on May 27, 2024

Good morning!
Training and fine-tuning of models is not yet implemented (the library is solely for evasion attacks).
However, if you would like to add this functionality, you can consider opening a pull request with that!

from secml_malware.

snehith57624 avatar snehith57624 commented on May 27, 2024

Getting error in training model when using embed function

    print("ok inside train 1")
    try:
        print("global_state.data_paths ", global_state.data_paths)
        for file_path in path:
            with open(file_path, 'rb') as handle:
                bytecode = handle.read()
            print("ok inside train 2")
            print("global_state.target ", global_state.target)
            net: CClassifierEnd2EndMalware = global_state.target
            x = End2EndModel.bytes_to_numpy(bytecode, net.get_input_max_length(), net.get_embedding_value(),
                                            net.get_is_shifting_values())

            model = MalConv()
            model.train(True)
            criterion = nn.BCELoss()
            optimizer = Adam(model.parameters(), lr=0.01)
            scheduler = ReduceLROnPlateau(optimizer, patience=3, verbose=True, factor=0.5,
                                          threshold=0.001, min_lr=0.00001, mode='max')
            print("ok inside train 3")
            epochs = 3
            y_pred = 0
            for epoch in range(epochs):
                y_pred = model.embedd_and_forward(model.embed(x))
                loss = criterion(y_pred, label)
                optimizer.zero_grad()
                loss.backward()
                optimizer.step()
            model.eval()
            print("ok inside train 8")
            scheduler.step(f1_score(label, y_pred))
            print("ok inside train 4")
    except Exception as e:
        print(e)
    return model

Getting error : "Dimension out of range (expected to be in range of [-1, 0], but got 1)"
Can you help to resolve this

Thanks

from secml_malware.

zangobot avatar zangobot commented on May 27, 2024

Hello,

Probably y_train is just a number and not a batch as expected by the loss.
Check which shapes the loss needs first, let me know!

from secml_malware.

snehith57624 avatar snehith57624 commented on May 27, 2024

Thanks got that cleared now my malconv model is predicting as trained but when I see the output it doesn't have prediction properly printed.

def _perform_optimization(attack, file_path, stats, x, y):
print('-' * 10)
info_prompt(f'Processing {file_path}...')
y_pred, adv_score, adv_ds, f_obj = attack.run(x, y)
y_pred = y_pred.item()

score = adv_score[0, 1].item()
stats['evasion'] += (1 - y_pred)
stats['total'] += 1
stats['adv_score'] += score
net = create_wrapper_for_global_target()
_, original_score = net.predict(x, return_decision_function=True)
stats['before_score'] += original_score[0, 1]
info_prompt(f'Results for {file_path}')
info_prompt(f'Final label: {y_pred}')
info_prompt(f'Initial score: {original_score}')
info_prompt(f'Final score: {score}')
return adv_ds

In the above code in line : _, original_score = net.predict(x, return_decision_function=True)
the first argument is the prediction label but it is not we are printing may I know the reason?

from secml_malware.

zangobot avatar zangobot commented on May 27, 2024

I don't think I got the question: if you set the "return_decision_function" to True, the output is the prediction and the score. The prediction is "score > threshold", hence 1 if malware, 0 if goodware.
Score is a CArray with two entries: first is goodware score, the second is malware (and they sum to 1)

from secml_malware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.