Preheat the oven to 190C/375°F Put the beans in a large bowl and mash lightly with a fork. Add the eggs and cheese and whisk with the fork until combined.
Put 2 tablespoons of the oil in a small skillet over medium-high heat. When the oil is hot, stir in the onion and garlic and cook, stirring frequently until they are soft and golden. Stir in the rosemary and remove from the heat.
Put the flour, baking powder, and a sprinkling of salt and pepper into the bowl with the beans. Add the onion mixture and stir with the fork until just combined. It should be like thick cookie dough - add more flour if necessary.
Use the remaining oil to grease a baking sheet. Use a large spoon or your hands to form the bean mixture into 8 bean cakes and put them on the prepared pan. Bake until golden and crisp, about 30 minutes and serve hot.
Serve with a little extra cheese and a side salad.