A Generalized Framework for Microstructural Optimization using Neural Networks