The in-medium nucleon-nucleon (NN) cross sections depend on the motion states of the colliding pair because of the influence of surrounding nucleons. As a result, these values are affected by total number density, isospin asymmetry, colliding pair total momentum, and total kinetic energy in the center-of-mass frame. This dependence is quite complicated, and the fitting based on functional form demonstrates some flaws in accuracy. Meanwhile, owing to the advantages of machine learning and neural networks in data fitting, we take the effective NN cross sections calculated by the microscopic method as a set of data and train these data using the deep neural network method to obtain the NN cross section under various conditions. The result demonstrates the remarkable advantage of machine learning in fitting the in-medium NN cross section. Furthermore, the cross section that was found using the neural network method can be applied to study the in-medium effects on the nuclear reaction observables within the transport models.