This is a procedure for factory reset if you need to proceed with it.
1- Device# factory-reset all --> Wait until you see the "switch:" prompt. After this step, there is no IOS on the switch at this moment. Only ROMMON. (NOTE: nothing will remain on the switch. This command will delete everything.)
https://www.cisco.com/c/en/us/td/docs/switches/lan/catalyst9300/software/release/16-11/configuration_guide/sys_mgmt/b_1611_sys_mgmt_9300_cg/simplified_factory_reset.html#reference_lmb_kmw_wbb
2- Load the required IOS into an external USB flash disk and insert this USB flash disk into the switch's USB port.
Device# boot usbflash0:cat9k_iosxe.17.12.04.SPA.bin --> Run a temporary IOS from the external flash disk and wait until load the temp IOS.
3- Once the temp IOS is loaded you can run regular commands as usual.
4- Follow the next steps. (Enter enable password, save the configuration etc.) Temp IOS will give you the flexibility to run the regular commands as usual.
5- Switch(config)# boot system flash:packages.conf --> Execute the boot command before installing the actual IOS to the device.
6- Switch#install add file flash:cat9k_iosxe.17.12.04.SPA.bin activate commit --> This command will install the permanent IOS to the device.
7- Follow the regular steps and configure regular items such as ports.