saving the images to a folder with custom filenames
Most of the code you provided doesn't do much to help your actual problem of renaming the files. I will just focus on tha tpart by showing you how to get the filenames you want.

You can rename the files, as you describe them, like this - assuming you have a list of filenames that match your description.

filenames = ['1.0.2.34.57_1.png', '1.0.2.34.58_1.png', '1.0.2.34.59_1.png']

for file in filenames:

    # Do what you want with the file...
    # Image processing and modelling, etc.


    # Replace the extension with your custom ending
    final_filename = file.replace('.png', '_mask.png')




Another way to do it, breaking down the removal and addition into two steps

for file in filenames:
    file_without_ext = file.replace('.png', '')

    # Add you custom ending
    final_filename = file_without_extension + '_mask.png'

    # Another variant - joining the extension to the file_without_ext using "_"
    final_filename = '_'.join(file_without_ext, 'mask.png')


The three variants of final_filename will be identical.

Now you can save the output of your image processing using the final_filename.