hi @ptrblck thanks for your answer. I’m actually new and i’m still learning this concepts.
I did remove the softmax activation from the pytorch net and didn’t change anything.
This is the code I’m using to transfer weights from keras to pytorch its the code that i found in the github:
def keras_to_pyt(km, pm):
weight_dict = OrderedDict()
for layer in km.layers:
if type(layer) is keras.layers.Conv2D:
weight_dict[layer.get_config()[‘name’] + ‘.weight’] = np.transpose(layer.get_weights()[0], (3, 2, 0, 1))
print(layer.get_config()[‘name’])
#print(weight_dict[layer.get_config()[‘name’] + ‘.weight’])
weight_dict[layer.get_config()[‘name’] + ‘.bias’] = layer.get_weights()[1]
elif type(layer) is keras.layers.Dense:
weight_dict[layer.get_config()[‘name’] + ‘.weight’] = np.transpose(layer.get_weights()[0], (1, 0))
weight_dict[layer.get_config()[‘name’] + ‘.bias’] = layer.get_weights()[1]
pyt_state_dict = pm.state_dict()
#print(pyt_state_dict)
#print(weight_dict)
print(pyt_state_dict.keys())
for key in pyt_state_dict.keys():
print(key)
if “flatten” in key:
print(“flatten layer no weights or biases”)
continue
    key1 = remove_prefix(key,"layers.")
    pyt_state_dict[key] = torch.from_numpy(weight_dict[key1])
    #print(pyt_state_dict[key])
pm.load_state_dict(pyt_state_dict)
return pm