Spaces:
Sleeping
Sleeping
| import os | |
| import numpy as np | |
| import onnxruntime as ort | |
| from PIL import Image | |
| LATENT_FEATURES = 512 | |
| MODEL_PATH = os.path.join("model", "batik_dcgan.onnx") | |
| model = ort.InferenceSession(MODEL_PATH) | |
| input_name = model.get_inputs()[0].name | |
| def generate_dcgan(): | |
| noise = np.random.randn(1, LATENT_FEATURES, 1, 1).astype(np.float32) | |
| output = model.run(None, { | |
| input_name: noise | |
| }) | |
| image = output[0][0] | |
| image = (image * 0.5 + 0.5) * 255 | |
| image = image.astype(np.uint8) | |
| image = np.transpose(image, (1, 2, 0)) | |
| pil_img = Image.fromarray(image, 'RGB') | |
| return pil_img.resize((512, 512), Image.LANCZOS) |