With recent train derailments in context, and railways allocating a significant part of its budget for safety, here is a solution that might work,
Taking the self driving cars with tube less tires and putting them on rail tracks so that they travel ahead of the trains at distances (less than a 1km) that allow for emergency braking of the train should this pilot vehicle hit an obstacle, derail or detect a hazard. The pilot vehicle has live CCTV feed looking ahead as well as at the tracks for issues, the CCTV feed is sent to the locomotive over a two way RF link. Image processing software can flag hazards in real time for the train crew to act on. Its sensors should work in night and foggy conditions as well.
It would also have a "red lamp" on top, something that is suitable for Indian environment. if a fire engine is approaching we can hear from enough distance.
This pilot vehicle is synced to the speed of the train increasing or decreasing the distance to enable safe braking of the train. Most of us trip on the safety aspect of such an arrangement. if the RF link fails the driver stops the train reducing the chance of the train hitting the pilot vehicle. Alternate communication nodes are setup along the tracks if the RF link is prone to disruption due to natural obstructions such as hilly terrain or tunnels. Without going into the "design" too much, these are some of the expected characteristics, the vehicle ought to be light weight so its acceleration is comparable to that of a motorbike with a truck and in the remote case of the train hitting it, its pushed out of the way. FRP can be used for the vehicle body. The vehicle can step aside the tracks using its own power also useful during train shunting operations.
They should have enough endurance to travel non-stop maybe equipped with 2 engines switching every few hours. To maintain their reliability should be replaced within few years of service. At 11000 trains on the rail network, a fleet of 15000 or so can be used which is typical of the operations of a big car rental company. Railways should really outsource such work and the sensors themselves should be outsourced to technology partners.
On self driving cars,https://www.indianagazette.com/news/reg-national-world/selfdriving-car-prototypes-need-less-human-help-data-show,25819398/
The scenarios faced on a contained system like rail tracks is less than that of traveling on roads so the rate of false alarms is low.
car on rail tracks,https://www.youtube.com/watch?v=LaZ4BCdJE-0