Imperia has a train station — actually two, one in Oneglia and one in Porto Maurizio — on the coastal line that runs between Genoa and Nice. Trains from Genoa take around 90 minutes; from Nice around an hour. The stations are about two kilometres apart, so check which one is closer to your accommodation before booking. Frequent regional trains stop at both.
By car, the A10 autostrada runs along the coast and exits directly into the town. The drive from Genoa takes around an hour; from Nice about 45 minutes. Driving along the old Via Aurelia rather than the motorway is slower but considerably more scenic — the coastal road passes through a series of small towns and offers sea views throughout.