Stable Diffusion in Java (SD4J) Enables Generating Images with Deep Learning – InfoQ.com
Oracle Open Source has introduced the Stable Diffusion in Java (SD4J) project, a modified port of the Stable Diffusion C# implementation with support for negative text inputs. Stable diffusion is a deep learning text-to-image model based on diffusion. SD4J can be used, via the GUI or programmatically in Java applications, to generate images. SD4J runs on top of the ONNX Runtime, a cross platform inference and training machine learning accelerator, allowing faster customer experience and reduced model training time.
Git Large File Storage, a Git extension for versioning large files, should be installed first, for example with the following command on Linux:
Afterwards, the SD4J project can be cloned locally with the following command:
SD4J uses models, the compatible pre-built ONNX models from Hugging Face, that will be used for the examples in this news story:
The README contains more information on using other models, such as those not in ONNX format.
ONNXRuntime-Extensions is a library which extends the capabilities of the ONNX models and the interference with the ONNX Runtime:
After cloning the project, the following command can be executed inside the onnxruntime-extensions directory to compile the ONNXRuntime-Extensions for your platform:
The following error might be displayed if CMake isn't installed:
Install at least version 3.25 of CMake to resolve the error, for example with the following command on Linux:
When the build is successful, the resulting library (libortextensions.[dylib,so] or ortextensions.dll) can be found inside the following directory:
The resulting library should be copied to the root directory of the SD4J project.
After these preparations, the GUI can be started by executing the Maven command, containing the model path, inside the sd4j directory:
The SD4J GUI is shown after the Maven command executed successfully:
The images in this news story are created with guidance scale 10, seed 42, inference steps 50 and image scheduler Euler Ancestral, unless stated otherwise.
First, the GUI is used to create an image of a sports car on the road, with the following image text:
This results in a red sports car on a road:
When generating images of sports cars, most of them are red. In order to create images with sports cars that aren't red, the image negative text may be used to specify what the image shouldn't contain. For example, by using the value red for image negative text, a white car is generated in this example:
The guidance scale indicates whether the resulting image should be closely related to the text prompt. A higher number indicates that they should be closely related. Conversely, a lower number may be used if more creativity in the image is desired. For stable diffusion, most models use a default guidance scale value between 7 and 7.5.
A clear picture of a house on a hill surrounded by trees is generated using the image text: Professional photograph of house on a hill, surrounded by trees, while it rains, high resolution, high quality and guidance scale 10:
Using the same image text with guidance scale 1allows more creativity and the house is now a bit hidden between the trees and the hill is less visible:
The seed is a random number used to generate noise. The generated images stay the same when using the same seed, prompt and other parameters.
Stable diffusion starts with an image of random noise. With each inference step, the noise is reduced and steered towards the prompt. Higher is not always better as it might introduce unwanted details. The Hugging Face website in general recommends 50 inference steps.
Creating an image of a tree in a park with inference 10 results in a relatively noisy tree image:
Increasing the inference steps to 50 results in a clearer image of a tree:
While increasing the inference steps further to 200 results in an image clearly displaying multiple trees and some other elements, for example in red:
The image scheduler takes a model's output to return a denoised version, while the batch size specifies the amount of generated images.
Working manually via the GUI allows generating images, however the project also provides the SD4J Java class to access SD4J programmatically.
Faster image generation is possible after enabling the CUDA integration for NVIDIA GPUs by changing the exec-maven-plugin in the pom.xml from
More information can be found in the SD4J README and the Hugging Face documentation provides additional information about the different concepts.
Read the original:
Stable Diffusion in Java (SD4J) Enables Generating Images with Deep Learning - InfoQ.com
- Ultrabroadband and band-selective thermal meta-emitters by machine learning - Nature - July 4th, 2025 [July 4th, 2025]
- Machine Learning is Surprisingly Good at Simulating the Universe - Universe Today - July 4th, 2025 [July 4th, 2025]
- Machine learning-assisted multi-dimensional transcriptomic analysis of cytoskeleton-related molecules and their relationship with prognosis in... - July 4th, 2025 [July 4th, 2025]
- Machine learning combined with multi-omics to identify immune-related LncRNA signature as biomarkers for predicting breast cancer prognosis - Nature - July 4th, 2025 [July 4th, 2025]
- Comprehensive machine learning analysis of PANoptosis signatures in multiple myeloma identifies prognostic and immunotherapy biomarkers - Nature - July 4th, 2025 [July 4th, 2025]
- Enhancing game outcome prediction in the Chinese basketball league through a machine learning framework based on performance data - Nature - July 4th, 2025 [July 4th, 2025]
- A novel double machine learning approach for detecting early breast cancer using advanced feature selection and dimensionality reduction techniques -... - July 4th, 2025 [July 4th, 2025]
- Machine learning for Parkinsons disease: a comprehensive review of datasets, algorithms, and challenges - Nature - July 4th, 2025 [July 4th, 2025]
- Cervical cancer prediction using machine learning models based on routine blood analysis - Nature - July 4th, 2025 [July 4th, 2025]
- Enhancing anomaly detection in IoT-driven factories using Logistic Boosting, Random Forest, and SVM: A comparative machine learning approach - Nature - July 4th, 2025 [July 4th, 2025]
- Predicting car accident severity in Northwest Ethiopia: a machine learning approach leveraging driver, environmental, and road conditions - Nature - July 4th, 2025 [July 4th, 2025]
- Sensormatic Solutions Adds Machine Learning to Shrink Analyzer - Ink World magazine - July 4th, 2025 [July 4th, 2025]
- Exploring the link between the ZJU index and sarcopenia in adults aged 2059 using NHANES and machine learning - Nature - July 4th, 2025 [July 4th, 2025]
- Combining multi-parametric MRI radiomics features with tumor abnormal protein to construct a machine learning-based predictive model for prostate... - July 2nd, 2025 [July 2nd, 2025]
- New insight into viscosity prediction of imidazolium-based ionic liquids and their mixtures with machine learning models - Nature - July 2nd, 2025 [July 2nd, 2025]
- Implementing partial least squares and machine learning regressive models for prediction of drug release in targeted drug delivery application -... - July 2nd, 2025 [July 2nd, 2025]
- Advanced analysis of defect clusters in nuclear reactors using machine learning techniques - Nature - July 2nd, 2025 [July 2nd, 2025]
- Machine learning analysis of kinematic movement features during functional tasks to discriminate chronic neck pain patients from asymptomatic controls... - July 2nd, 2025 [July 2nd, 2025]
- Enhanced machine learning models for predicting three-year mortality in Non-STEMI patients aged 75 and above - BMC Geriatrics - July 2nd, 2025 [July 2nd, 2025]
- Modeling seawater intrusion along the Alabama coastline using physical and machine learning models to evaluate the effects of multiscale natural and... - July 2nd, 2025 [July 2nd, 2025]
- A comprehensive study based on machine learning models for early identification Mycoplasma pneumoniae infection in segmental/lobar pneumonia - Nature - July 2nd, 2025 [July 2nd, 2025]
- Identifying ovarian cancer with machine learning DNA methylation pattern analysis - Nature - July 2nd, 2025 [July 2nd, 2025]
- High-isolation dual-band MIMO antenna for next-generation 5G wireless networks at 28/38 GHz with machine learning-based gain prediction - Nature - July 2nd, 2025 [July 2nd, 2025]
- Sony and AMD want to focus on machine learning for the PS6 - Instant Gaming News - July 2nd, 2025 [July 2nd, 2025]
- How Machine Learning is Reshaping the Future of Sports Betting? - London Daily News - July 2nd, 2025 [July 2nd, 2025]
- An interpretable machine learning model for predicting depression in middle-aged and elderly cancer patients in China: a study based on the CHARLS... - July 2nd, 2025 [July 2nd, 2025]
- These Eight Projects Showcase the Power of Machine Learning on the Edge - Hackster.io - June 29th, 2025 [June 29th, 2025]
- Build Custom AI Tools for Your AI Agents that Combine Machine Learning and Statistical Analysis - MarkTechPost - June 29th, 2025 [June 29th, 2025]
- Check out these essential tips and trends for SEO in 2025 as AI and machine learning loom large - EdTech Innovation Hub - June 29th, 2025 [June 29th, 2025]
- Using machine learning to predict the severity of salmonella infection - Open Access Government - June 28th, 2025 [June 28th, 2025]
- How AI and machine learning are transforming drug discovery - Pharmaceutical Technology - June 28th, 2025 [June 28th, 2025]
- Capturing the complexity of human strategic decision-making with machine learning - Nature - June 26th, 2025 [June 26th, 2025]
- A framework to evaluate machine learning crystal stability predictions - Nature - June 24th, 2025 [June 24th, 2025]
- Machine learning revealed giant thermal conductivity reduction by strong phonon localization in two-angle disordered twisted multilayer graphene -... - June 24th, 2025 [June 24th, 2025]
- How AI and Machine Learning Are Powering the Next Generation of Pump Maintenance - Robotics Tomorrow - June 24th, 2025 [June 24th, 2025]
- Actuate Therapeutics Reports Positive Biomarker and Machine Learning Data from Phase 2 Elraglusib Trial in First-Line Treatment of Metastatic... - June 24th, 2025 [June 24th, 2025]
- Texas A&M Researchers Introduce a Two-Phase Machine Learning Method Named ShockCast for High-Speed Flow Simulation with Neural Temporal Re-Meshing -... - June 22nd, 2025 [June 22nd, 2025]
- Machine learning method helps bring diagnostic testing out of the lab - Medical Xpress - June 22nd, 2025 [June 22nd, 2025]
- Sebi proposes five-point rulebook for responsible use of AI, machine learning - The New Indian Express - June 22nd, 2025 [June 22nd, 2025]
- HAPIR: a refined Hallmark gene set-based machine learning approach for predicting immunotherapy response in cancer patients - Nature - June 20th, 2025 [June 20th, 2025]
- Machine learning boosts accuracy of point-of-care disease detection - News-Medical - June 20th, 2025 [June 20th, 2025]
- How AI and Machine Learning Are Transforming Food Poisoning Outbreak Detection - Food Poisoning News - June 20th, 2025 [June 20th, 2025]
- Evo 2 machine learning model enlists the power of AI in the fight against diseases - Medical Xpress - June 20th, 2025 [June 20th, 2025]
- Machine learning can predict which babies will be born with low birth weights - Medical Xpress - June 20th, 2025 [June 20th, 2025]
- Development and Validation of a Machine Learning Model for Identifying Novel HIV Integrase Inhibitors - Cureus - June 20th, 2025 [June 20th, 2025]
- IIT launches new online certificate programme in data science and machine learning for working profession - Times of India - June 20th, 2025 [June 20th, 2025]
- Calgary startup tackles referee abuse with microphones and machine learning - Yahoo - June 20th, 2025 [June 20th, 2025]
- New machine learning program accurately predicts who will stick with their exercise program - AOL.com - June 20th, 2025 [June 20th, 2025]
- Machine learning and generative AI: What are they good for in 2025? - MIT Sloan - June 4th, 2025 [June 4th, 2025]
- Researchers use machine learning to improve gene therapy - Stanford Report - June 4th, 2025 [June 4th, 2025]
- Machine learning for workpiece mass prediction using real and synthetic acoustic data - Nature - June 4th, 2025 [June 4th, 2025]
- Analyzing the Effect of Linguistic Similarity on Cross-Lingual Transfer: Tasks and Input Representations Matter - Apple Machine Learning Research - June 4th, 2025 [June 4th, 2025]
- Machine learning models for predicting severe acute kidney injury in patients with sepsis-induced myocardial injury - Nature - June 4th, 2025 [June 4th, 2025]
- A machine learning approach to carbon emissions prediction of the top eleven emitters by 2030 and their prospects for meeting Paris agreement targets... - June 4th, 2025 [June 4th, 2025]
- Augmentation of wastewater-based epidemiology with machine learning to support global health surveillance - Nature - June 4th, 2025 [June 4th, 2025]
- Analysis of a nonsteroidal anti inflammatory drug solubility in green solvent via developing robust models based on machine learning technique -... - June 4th, 2025 [June 4th, 2025]
- Your DNA Is a Machine Learning Model: Its Already Out There - Towards Data Science - June 4th, 2025 [June 4th, 2025]
- Development and validation of a risk prediction model for kinesiophobia in postoperative lung cancer patients: an interpretable machine learning... - June 4th, 2025 [June 4th, 2025]
- Predicting long-term patency of radiocephalic arteriovenous fistulas with machine learning and the PREDICT-AVF web app - Nature - June 4th, 2025 [June 4th, 2025]
- How Machine Learning and Cascade Learning Open Doors of Advanced Automation - Supply & Demand Chain Executive - June 4th, 2025 [June 4th, 2025]
- New Hydrogenation Reaction Mechanism for Superhydride Revealed by Machine Learning - Asia Research News | - June 4th, 2025 [June 4th, 2025]
- AI experiences rapid adoption, but with mixed outcomes Highlights from VotE: AI & Machine Learning - S&P Global - June 4th, 2025 [June 4th, 2025]
- IIPE introduces online M.Tech in Data Science and Machine Learning for working professionals - India Today - June 4th, 2025 [June 4th, 2025]
- Introducing Windows ML: The future of machine learning development on Windows - Windows Blog - May 19th, 2025 [May 19th, 2025]
- Settlement strategies and their driving mechanisms of Neolithic settlements using machine learning approaches: a case study in Zhejiang Province -... - May 19th, 2025 [May 19th, 2025]
- MyWear revolutionizes real-time health monitoring with comparative analysis of machine learning - Nature - May 19th, 2025 [May 19th, 2025]
- Leveraging stacking machine learning models and optimization for improved cyberattack detection - Nature - May 19th, 2025 [May 19th, 2025]
- Predicting land suitability for wheat and barley crops using machine learning techniques - Nature - May 10th, 2025 [May 10th, 2025]
- AI and Machine Learning - Ribeiro Preto adopts Optibus to optimise public bus system - Smart Cities World - May 10th, 2025 [May 10th, 2025]
- Childrens Hospital Los Angeles Leads Development of First Machine Learning Tool to Predict Risk of Cisplatin-Induced Hearing Loss - Business Wire - May 10th, 2025 [May 10th, 2025]
- Google is using machine learning to help Android users avoid unwanted and dangerous notifications - BetaNews - May 10th, 2025 [May 10th, 2025]
- London School of Emerging Technology (LSET) Concludes International Workshop on Emerging AI & Machine Learning Innovation - Barchart.com - May 10th, 2025 [May 10th, 2025]
- Thermal performance, entropy generation, and machine learning insights of AlO-TiO hybrid nanofluids in turbulent flow - Nature - May 10th, 2025 [May 10th, 2025]
- Predicting the efficacy of bevacizumab on peritumoral edema based on imaging features and machine learning - Nature - May 10th, 2025 [May 10th, 2025]
- How AI and machine learning are supercharging video conferencing tools - European CEO - May 10th, 2025 [May 10th, 2025]
- The need for a risk-based approach to AI and machine learning in healthcare - Health Tech World - May 10th, 2025 [May 10th, 2025]
- Integrated bioinformatics, machine learning, and molecular docking reveal crosstalk genes and potential drugs between periodontitis and systemic lupus... - May 10th, 2025 [May 10th, 2025]
- Adversarial Machine Learning in Detecting Inauthentic Behavior on Social Platforms - AiThority - May 10th, 2025 [May 10th, 2025]
- Exploring crop health and its associations with fungal soil microbiome composition using machine learning applied to remote sensing data - Nature - May 10th, 2025 [May 10th, 2025]
- Trust-based model and machine learning improve forest fire detection system - International Fire & Safety Journal - May 10th, 2025 [May 10th, 2025]