Can instrument training be done in IMC with an instrument-rated safety pilot?
If you are the sole manipulator of the controls then yes you can log PIC time in this scenario, however you cannot act as PIC. The FAA discusses this in at least two letters of interpretation Speranza 2009 and Walker 2011. Both which lay out effectively the same situation (I would advise reading them) but in short they go into the fact that acting as PIC is not the same as being the sole manipulator of the controls and thus logging time as PIC.
Interestingly the IFR Rated pilot cannot log the PIC time while you are the sole manipulator of the controls as there is no prevision for that in the safety pilot regulations. The FAA words it as follows:

However, Pilot A may not log PIC time for the portion of the flight during which Pilot B is the sole manipulator of the controls, and is logging PIC time, because there is no provision for this logging in 61.51(e)
...
Although Pilot B [non IFR Rate Pilot] properly may log PIC time for a
portion of the flight as discussed previously, Pilot B could not act
as PIC and was not a required flight crew member for any portion of
the flight under the aircraft's type certificate or the regulations
under which the flight was conducted.
Speranza 2009

If you are in IMC then you do not need a hood as you would log that as actual IMC
The Herman Interpretation (2009) may also be relevant reading r.e. logging PIC vs Being PIC