# save weights of TensorFlow model tf_model.save_weights("model_weights.h5") import keras keras.config.set_backend("torch") from keras3_vit import TFViTForImageClassification as Keras3ViT keras3_model = Keras3ViT() # call model to initializate all layers keras3_model(torch_input, training=False) # load the weights from the TensorFlow model keras3_model.load_weights("model_weights.h5") # validate converted model assert isinstance(keras3_model, torch.nn.Module) keras3_model = keras3_model.to(DEVICE) keras3_model = keras3_model.eval() torch_output = keras3_model(torch_input, training=False) torch_output = torch_output[0].detach().cpu().numpy() print("Max diff:", np.max(np.abs(tf_output - torch_output))) num_pyt_params = sum([p.numel() for p in keras3_model.parameters() if p.requires_grad]) print(f"Keras3 Trainable Parameters: {num_pyt_params:,}")