eiisolver / LegendsOfCodeAndMagic

Report of AI contest hosted by www.codingame.com
1 stars 0 forks source link

Question #1

Open Nivekiba opened 5 years ago

Nivekiba commented 5 years ago

Hello EiiSolver, me too i'm on codingame. For some contest i wanna use neural network (keras also) but i don't knew how to import the training results in CG. So my question is how do you do that ? Thanks a lot for reading. I'm waiting for your response

eiisolver commented 5 years ago

Hi, I use the following function to generate (horrible) C++ code containing the model's weights: def output_layers(file, model, function_name): i = 0 file.write('#include "ff_net.h"\n') file.write('void %s(FFNet &net) {\n' % (function_name)) for layer in model.layers: i = i + 1 weights = layer.getweights()[0] for j in range(0, len(weights)): file.write('static double w%d%d[] = ' % (i, j)) printarray(file, weights[j]) file.write('net.layers[%d].weights = {' % (i)) for j in range(0, len(weights)): file.write('w%d%d, ' % (i, j)) file.write('};\n') file.write('net.layers[%d].bias = ' % (i)) print_array(file, layer.get_weights()[1]) file.write('}\n')

where model is a keras model (models.Sequential, only dense layers are supported by my export function); my LOCM model is:

model = models.Sequential()
model.add(layers.Dense(30, activation='relu', input_shape=inp_shape,

use_bias=True)) model.add(layers.Dense(1, activation='sigmoid'))

FFNet is a home-written C++ class that can perform feed-forward calculation for the neural network.

Good luck!

Den ons 12 sep. 2018 kl 22:19 skrev Nivekiba notifications@github.com:

Hello EiiSolver, me too i'm on codingame. For some contest i wanna use neural network (keras also) but i don't knew how to import the training results in CG. So my question is how do you do that ? Thanks a lot for reading. I'm waiting for your response

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/eiisolver/LegendsOfCodeAndMagic/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/ABV201bzhpv8qhy1NdVYqHPRIjjHiXV2ks5uaWxhgaJpZM4WmGLC .

Nivekiba commented 5 years ago

ah..ok so <ff_net,h> is present in c++ librairies in CG ??

eiisolver commented 5 years ago

No, you have to write an implementation yourself... I have a home written tool that allows me to write code in multiple source files and from those files creates one cpp file that can be copied to CG.

Den tors 13 sep. 2018 11:36Nivekiba notifications@github.com skrev:

ah..ok so <ff_net,h> is present in c++ librairies in CG ??

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eiisolver/LegendsOfCodeAndMagic/issues/1#issuecomment-420946027, or mute the thread https://github.com/notifications/unsubscribe-auth/ABV208xJrwm-bqEIxamy8dGH9BIRBw7Uks5uaicogaJpZM4WmGLC .

Nivekiba commented 5 years ago

No, you have to write an implementation yourself... I have a home written tool that allows me to write code in multiple source files and from those files creates one cpp file that can be copied to CG. Den tors 13 sep. 2018 11:36Nivekiba notifications@github.com skrev: ah..ok so <ff_net,h> is present in c++ librairies in CG ?? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#1 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ABV208xJrwm-bqEIxamy8dGH9BIRBw7Uks5uaicogaJpZM4WmGLC .

you implement ff_net.h your self ? That's not too much work ?