elleryqueenhomels / fast_neural_style_transfer

Generative Neural Methods Based On Model Iteration
MIT License
515 stars 90 forks source link

Unable to produce example results #9

Open justnajm opened 11 months ago

justnajm commented 11 months ago

Hi, thanks for such fast model, I have tried your code and followed steps. So, initially I am getting this error:

TypeError: Cannot handle this data type: (1, 1, 3), <f4

Traceback (most recent call last): File "F:\ai\deep\fast_neural_style_transfer-dev\main.py", line 71, in <module> main() File "F:\ai\deep\fast_neural_style_transfer-dev\main.py", line 64, in main generated_images = generate(content_targets, model_path, save_path=output_save_path, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\ai\deep\fast_neural_style_transfer-dev\generate.py", line 23, in generate outputs = _handler2(contents_path, model_path, save_path=save_path, prefix=prefix, suffix=suffix) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\ai\deep\fast_neural_style_transfer-dev\generate.py", line 72, in _handler2 save_images(content_path, output, save_path, prefix=prefix, suffix=suffix) File "F:\ai\deep\fast_neural_style_transfer-dev\utils.py", line 61, in save_images imsave(path, data) File "C:\Users\Najm Abideen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\imageio\v2.py", line 397, in imwrite return file.write(im, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Najm Abideen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\imageio\plugins\pillow.py", line 425, in write pil_frame = Image.fromarray(frame, mode=mode) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Najm Abideen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\PIL\Image.py", line 3073, in fromarray raise TypeError(msg) from e TypeError: Cannot handle this data type: (1, 1, 3), <f4

I skipped the error and tried to show the result using: plt.imshow(result[0], interpolation='nearest') plt.show()

but generated result[0] is an empty image, I have seen very little generated noise on following styles:

'wave': [1.0, 7.0, 1e-2], #-

'scream': [1.0, 60.0, 1e-2], #-

'rain_princess': [1.0, 8.0, 1e-2], #-

image

Actually, I have tried all of your pre trained 10 models. Have also placed the weights file, "imagenet-vgg-verydeep-19.mat" & "imagenet-vgg-19-weights.npz".

I finally was able to save the image using:

if save_path is not None:
    for i, image in enumerate(output):
        # Convert image to the appropriate data type and scale it to 0-255
        image_scaled = (image * 255).astype(np.uint8)
        # Save the image using imageio
        filename = f"{prefix}_{i}_{suffix}.png" if prefix and suffix else f"image_{i}.png"
        imageio.imwrite(f"{save_path}/{filename}", image_scaled)
    #save_images(content_path, output_converted, save_path, prefix=prefix, suffix=suffix)

but images are simply nothing but noise: image

Kindly help really appreciate, I don't know why I found this code so late :)

elleryqueenhomels commented 11 months ago

Hi, thank you for reaching out.

Just double confirm, were you using the dev branch? If so, please switch to master branch and use the correct python lib version.