With the growing quantity of vehicles, traffic security is in a grim state. In order to improve the safety of road traffic, this paper proposes a forecasting algorithm of traffic accident risk based on deep learning for edge-cloud internet of vehicles. Specifically, the gathered real-time traffic data is input into a convolutional neural network (CNN) for feature extraction. Then, the output of CNN is input in a random forest for feature classification, and the risk of traffic accidents can be predicted. The edge servers pick the warnings with the high risk of traffic accidents and transmit them to the corresponding vehicle units. The drivers can reduce the risk of traffic accidents via adjusting their behaviors according to the warnings. Simulations show that the proposed forecasting algorithm has a larger area under the curve of Receiver Operating Characteristic, higher accuracy, and lower loss than the CNN based method.