Preheat the oven to 350°F (175°C) and grease and flour two 9-inch round cake pans.
Whisk together the flour, sugar, baking powder, baking soda, cinnamon, and salt in a large mixing bowl.
Combine the vegetable oil, eggs, and vanilla extract in another bowl.
Gradually add the wet mixture to the dry ingredients, mixing until just combined.
Fold in the grated carrots and walnuts (if using) gently.
Divide the batter evenly between the prepared cake pans.
Bake for 30-40 minutes or until a toothpick inserted in the center comes out clean.
Cool the cakes in the pans for 10 minutes before transferring them to a wire rack to cool completely.
Beat the softened cream cheese and butter together in a mixing bowl until smooth.
Gradually add powdered sugar and vanilla extract, mixing until creamy and well combined.
Place one cooled cake layer on a serving plate.
Spread a layer of frosting on top of this first layer before placing the second cake layer on top.
Frost the top and sides of the cake with any remaining frosting.
Decorate with additional walnuts if desired.