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
- Dietary intervention optimized using machine learning could lower risk of dementia - Medical Xpress - July 20th, 2025 [July 20th, 2025]
- Application of machine learning algorithms and SHAP explanations to predict fertility preference among reproductive women in Somalia - Nature - July 20th, 2025 [July 20th, 2025]
- From Reactive to Predictive: Forecasting Network Congestion with Machine Learning and INT - Towards Data Science - July 20th, 2025 [July 20th, 2025]
- Artificial intelligence and machine learning in the development of vaccines and immunotherapeuticsyesterday, today, and tomorrow - Frontiers - July 20th, 2025 [July 20th, 2025]
- How Machine Learning is Revolutionizing Threat Detection for Businesses in Real-Time - Eye On Annapolis - July 20th, 2025 [July 20th, 2025]
- Identification of clinical diagnostic and immune cell infiltration characteristics of acute myocardial infarction with machine learning approach -... - July 20th, 2025 [July 20th, 2025]
- Predicting the mechanical performance of industrial waste incorporated sustainable concrete using hybrid machine learning modeling and parametric... - July 20th, 2025 [July 20th, 2025]
- Integrative multi-omics and machine learning reveal critical functions of proliferating cells in prognosis and personalized treatment of lung... - July 20th, 2025 [July 20th, 2025]
- Systematic measurement and machine learning-based profile characterization of community noise in a medium-large city in the United States - Nature - July 20th, 2025 [July 20th, 2025]
- Prediction of birthweight with early and mid-pregnancy antenatal markers utilising machine learning and explainable artificial intelligence - Nature - July 20th, 2025 [July 20th, 2025]
- A comprehensive machine learning for high throughput Tuberculosis sequence analysis, functional annotation, and visualization - Nature - July 20th, 2025 [July 20th, 2025]
- AI and Machine Learning Skills Are Make or Break for Developers: 71% of Tech Leaders Wont Hire Without Them - The National Law Review - July 20th, 2025 [July 20th, 2025]
- Quality-of-life scale machine learning approach to predict immunotherapy response in patients with advanced non-small cell lung cancer - Frontiers - July 20th, 2025 [July 20th, 2025]
- Inversion and validation of soil water-holding capacity in a wild fruit forest, using hyperspectral technology combined with machine learning - Nature - July 20th, 2025 [July 20th, 2025]
- Machine Learning in Drug Discovery Market to Witness Exponential Growth: Key Players, $250M Eli Lilly Deal & Regional Insights for 2025-2034 -... - July 18th, 2025 [July 18th, 2025]
- Automated seafood freshness detection and preservation analysis using machine learning and paper-based pH sensors - Nature - July 18th, 2025 [July 18th, 2025]
- Do You Know What It Means To Train a Machine Learning Model? - LSU - July 18th, 2025 [July 18th, 2025]
- Establishment of an interpretable MRI radiomics-based machine learning model capable of predicting axillary lymph node metastasis in invasive breast... - July 18th, 2025 [July 18th, 2025]
- A Machine Learning-Reconstructed Dataset of River Discharge, Temperature, and Heat Flux into the Arctic Ocean - Nature - July 18th, 2025 [July 18th, 2025]
- Leveraging computational linguistics and machine learning for detection of ultra-high risk of mental health disorders in youths | Schizophrenia -... - July 18th, 2025 [July 18th, 2025]
- Development and validation of machine learning-based diagnostic models using blood transcriptomics for early childhood diabetes prediction - Frontiers - July 18th, 2025 [July 18th, 2025]
- Fatigue and stamina prediction of athletic person on track using thermal facial biomarkers and optimized machine learning algorithm - Nature - July 18th, 2025 [July 18th, 2025]
- Identifying the crucial oncogenic mechanisms of DDX56 based on a machine learning-based integration model of RNA-binding proteins - Nature - July 18th, 2025 [July 18th, 2025]
- AI and Machine Learning Skills Are Make or Break for Developers: 71% of Tech Leaders Wont Hire Without Them - Yahoo Finance - July 18th, 2025 [July 18th, 2025]
- Developing an explainable machine learning and fog computing-based visual rating scale for the prediction of dementia progression - Nature - July 18th, 2025 [July 18th, 2025]
- Prognosis of air quality index and air pollution using machine learning techniques - Nature - July 18th, 2025 [July 18th, 2025]
- Integrating vision transformer-based deep learning model with kernel extreme learning machine for non-invasive diagnosis of neonatal jaundice using... - July 18th, 2025 [July 18th, 2025]
- PlayStation 6 Likely to Feature 24 GB RAM for Advanced Ray Tracing and Machine Learning Without Raising Costs - Wccftech - July 18th, 2025 [July 18th, 2025]
- Machine Learning-Assisted Iterative Screening for Efficient Detection of Drug Discovery Starting Points - ACS Publications - July 16th, 2025 [July 16th, 2025]
- 2025 IT Camp on AI & Machine Learning for Beginners to be held August 5 - Southeastern Oklahoma State University - July 16th, 2025 [July 16th, 2025]
- Utilizing machine learning to predict MRI signal outputs from iron oxide nanoparticles through the PSLG algorithm - Nature - July 16th, 2025 [July 16th, 2025]
- Developing a machine-learning model to enable treatment selection for neoadjuvant chemotherapy for esophageal cancer - Nature - July 16th, 2025 [July 16th, 2025]
- Advancing crop recommendation system with supervised machine learning and explainable artificial intelligence - Nature - July 16th, 2025 [July 16th, 2025]
- Predicting clozapine-induced adverse drug reaction biomarkers using machine learning - Nature - July 16th, 2025 [July 16th, 2025]
- Postoperative complication severity prediction in penile prosthesis implantation: a machine learning-based predictive modeling study - Nature - July 16th, 2025 [July 16th, 2025]
- The Future of AI & Machine Learning: Perspective on Shaping Tomorrows Business Landscape - Vocal - July 16th, 2025 [July 16th, 2025]
- Machine Learning: Your Ticket to a Thriving Career in the Tech World - The Impressive Times - July 14th, 2025 [July 14th, 2025]
- Integrative analysis of multi-omics data and gut microbiota composition reveals prognostic subtypes and predicts immunotherapy response in colorectal... - July 14th, 2025 [July 14th, 2025]
- Comprehensive multi-omics and machine learning framework for glioma subtyping and precision therapeutics - Nature - July 14th, 2025 [July 14th, 2025]
- Development and validation of a machine learning-based nomogram for survival prediction of patients with hilar cholangiocarcinoma after... - July 12th, 2025 [July 12th, 2025]
- Geochemical-integrated machine learning approach predicts the distribution of cadmium speciation in European and Chinese topsoils - Nature - July 12th, 2025 [July 12th, 2025]
- Machine learning-based construction of a programmed cell death-related model reveals prognosis and immune infiltration in pancreatic adenocarcinoma... - July 12th, 2025 [July 12th, 2025]
- Application of supervised machine learning and unsupervised data compression models for pore pressure prediction employing drilling, petrophysical,... - July 12th, 2025 [July 12th, 2025]
- Machine learning identifies lipid-associated genes and constructs diagnostic and prognostic models for idiopathic pulmonary fibrosis - Orphanet... - July 12th, 2025 [July 12th, 2025]
- An evaluation methodology for machine learning-based tandem mass spectra similarity prediction - BMC Bioinformatics - July 12th, 2025 [July 12th, 2025]
- The Rise of AI in Trading: Machine Learning and the Stock Market - Disruption Banking - July 12th, 2025 [July 12th, 2025]
- Integrative analysis identifies IL-6/JUN/MMP-9 pathway destroyed blood-brain-barrier in autism mice via machine learning and bioinformatic analysis -... - July 12th, 2025 [July 12th, 2025]
- Interpretive prediction of hyperuricemia and gout patients via machine learning analysis of human gut microbiome - BMC Microbiology - July 10th, 2025 [July 10th, 2025]
- Machine learning-based identification of key factors and spatial heterogeneity analysis of urban flooding: a case study of the central urban area of... - July 10th, 2025 [July 10th, 2025]
- Developing machine learning frameworks to predict mechanical properties of ultra-high performance concrete mixed with various industrial byproducts -... - July 10th, 2025 [July 10th, 2025]
- Small Drones Market Trend Analysis and Forecast Report 2025-2034 | AI and Machine Learning Revolutionizing Autonomous Operations, Trade Tariffs Push... - July 10th, 2025 [July 10th, 2025]
- When a model touches millions: Hatim Kagalwala on accuracy accountability, and applied machine learning - Dataconomy - July 10th, 2025 [July 10th, 2025]
- New Study Uses Gait Data and Machine Learning for Early Detection of Anxiety and Depression - AZoSensors - July 10th, 2025 [July 10th, 2025]
- Machine Learning and the Evolution of Mobile Apps - CIO Applications - July 10th, 2025 [July 10th, 2025]
- Artificial Intelligence, Machine Learning, and Big Data in Thailand: Legal and Regulatory Developments 2025 - Lexology - July 10th, 2025 [July 10th, 2025]
- Karen Hao on how the AI boom became a new imperial frontier - Machine Learning Week 2025 - July 8th, 2025 [July 8th, 2025]
- Machine Learning and AI in Enhancing Image Analysis of 3D Samples - Drug Target Review - July 8th, 2025 [July 8th, 2025]
- Gartner Predicts Over 40% of Agentic AI Projects Will Be Canceled by End of 2027 - Machine Learning Week 2025 - July 8th, 2025 [July 8th, 2025]
- Explainable machine learning model for predicting the transarterial chemoembolization response and subtypes of hepatocellular carcinoma patients - BMC... - July 8th, 2025 [July 8th, 2025]
- Identification and validation of glucocorticoid receptor and programmed cell death-related genes in spinal cord injury using machine learning - Nature - July 8th, 2025 [July 8th, 2025]
- Multiclass leukemia cell classification using hybrid deep learning and machine learning with CNN-based feature extraction - Nature - July 6th, 2025 [July 6th, 2025]
- Predictive modeling and machine learning show poor performance of clinical, morphological, and hemodynamic parameters for small intracranial aneurysm... - July 6th, 2025 [July 6th, 2025]
- A robust machine learning approach to predicting remission and stratifying risk in rheumatoid arthritis patients treated with bDMARDs - Nature - July 6th, 2025 [July 6th, 2025]
- 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]