If by "factory-reset", you're wanting to completely erase for Mac - possibly for resale, or just to start clean again - and you're concerned about losing data, there are some steps you can do before you do this.
I am going with the notion that you're paying for additional storage for iCloud. If not, I recommend you do.
Go to System-Preferences -> AppleID -> check "photos" to sync with iCloud. Best to make sure everything is checked for iCloud. If it is already checked, then your photos are already on the cloud, and will by synced back to your Mac - or any Mac - when you re-enter your AppleID.
You should make a backup of your machine just in case there are files somewhere that have not been backed up, or part of your iCloud integration.
You can also log into iCloud.com and view the photos that are currently synced to iCloud. If all your photos are there, you're good to go.
Follow the attached instructions. If you want to start with a completely clean machine, enter "Disk Utility" first and erase your entire Mac. When wiped out, exit out of disk utility and follow the instructions for reinstalling MacOS.
Good luck.
https://support.apple.com/en-us/HT204904