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
- Predicting Outcomes with Machine Learning | Mathematical Sciences | College of Arts & Sciences - University of Delaware - July 6th, 2026 [July 6th, 2026]
- Machine Learning in Public Health: A 3-day Intensive Workshop - American Public Health Association - July 6th, 2026 [July 6th, 2026]
- Tunable band-stop photodetection with machine learning-enabled broadband spectral adaptation - Nature - July 3rd, 2026 [July 3rd, 2026]
- Basic machine learning with lessR : Easy, simple, and free - Open Access Government - July 3rd, 2026 [July 3rd, 2026]
- QuadSci Named Machine Learning Company of the Year - MarTech Cube - July 3rd, 2026 [July 3rd, 2026]
- From Conventional to Intelligent Triage: A Systematic Review of Artificial Intelligence and Machine Learning Applications in Emergency Departments -... - July 3rd, 2026 [July 3rd, 2026]
- On Robustness and Chain-of-Thought Consistency of RL-Finetuned VLMs - Apple Machine Learning Research - July 3rd, 2026 [July 3rd, 2026]
- Improving Wildfire Prediction with Machine Learning and Firebreaks - University of Reading - July 3rd, 2026 [July 3rd, 2026]
- A 3X Leader for the Agentic Era: DataRobot Named a Leader Again in the Gartner Magic Quadrant for Data Science and Machine Learning Platforms -... - June 24th, 2026 [June 24th, 2026]
- A 3X Leader for the Agentic Era: DataRobot Named a Leader Again in the Gartner Magic Quadrant for Data Science and Machine Learning Platforms - Yahoo... - June 24th, 2026 [June 24th, 2026]
- Undergrads gain hands-on machine learning experience in summer program - The Pennsylvania State University - June 24th, 2026 [June 24th, 2026]
- Python and Machine Learning: Why the Two Skills Are Increasingly Inseparable - BNO News - June 24th, 2026 [June 24th, 2026]
- Domino Data Lab Named a Visionary for the Third Consecutive Year in the 2026 Gartner Magic Quadrant for AI Platforms for Data Science and Machine... - June 24th, 2026 [June 24th, 2026]
- Machine Learning Boosts Smart Thermochromic Window Efficiency - Bioengineer.org - June 24th, 2026 [June 24th, 2026]
- A.I. VS HUMAN ROAST BATTLE to Pit Machine Learning Against Live Rapper in SF - BroadwayWorld - June 16th, 2026 [June 16th, 2026]
- Machine learning gives the U.S. a 1% chance of winning the World Cup final in its own backyard - Fortune - June 16th, 2026 [June 16th, 2026]
- Machine Learning Reveals Genes That Help Yeasts Resist Stress - Department of Energy (.gov) - June 16th, 2026 [June 16th, 2026]
- Machine Learning Reveals AED Impact on LGG Prognosis - Bioengineer.org - June 16th, 2026 [June 16th, 2026]
- Introducing the Third Generation of Apples Foundation Models - Apple Machine Learning Research - June 12th, 2026 [June 12th, 2026]
- Machine learning model predicts T2D risk up to 10 years before onset - Managed Healthcare Executive - June 12th, 2026 [June 12th, 2026]
- GPU as a Service Market to Reach USD 14.4 Billion by 2033 at 16.0% CAGR, Fueled by Generative AI, Machine Learning, and Cloud Infrastructure Expansion... - June 12th, 2026 [June 12th, 2026]
- Machine learning-guided design of mechanoadaptive bioglues for multitissue trauma and first-aid applications - Nature - June 12th, 2026 [June 12th, 2026]
- OUCRU scientists are using machine learning to forecast the next dengue outbreak - tropicalmedicine.ox.ac.uk - June 12th, 2026 [June 12th, 2026]
- IIT Roorkee invites applications for 11th Batch of Data Science, Machine Learning & Generative AI Programme - Elets Technomedia - June 12th, 2026 [June 12th, 2026]
- RAG Is Not Machine Learning, and the ML Toolkit Solves the Wrong Problem - Towards Data Science - June 3rd, 2026 [June 3rd, 2026]
- A reality check on the AI jobs hysteria - Machine Learning Week US - June 3rd, 2026 [June 3rd, 2026]
- STMicroelectronics Releases Vibration Sensor With Integrated Machine Learning for Industrial Monitoring - geneonline.com - June 3rd, 2026 [June 3rd, 2026]
- NAVER LABS Europe is offering a 2026 Research Internship in Large Language Models, focusing on AI Alignment, Controlled Generation, and Machine... - May 29th, 2026 [May 29th, 2026]
- Q&A: A Machine-Learning-Based Tool to Enhance Clinical Care of Patients With Multiple Sclerosis - Physician's Weekly - May 29th, 2026 [May 29th, 2026]
- Evaluating the Diagnostic Performance of AI and Machine Learning in Sickle Cell Disease Detection: A Systematic Review - Cureus - May 29th, 2026 [May 29th, 2026]
- HTC-19 Update: Artificial Intelligence and Machine Learning - Chromatography Online - May 29th, 2026 [May 29th, 2026]
- Multimodal phenotypic classification of generalized anxiety and panic using structural MRI data and psychosocial factors: machine learning results... - May 29th, 2026 [May 29th, 2026]
- Machine Learning Personalizes Depression Treatment with the Help of Wearable Technology - UC San Diego Today - May 27th, 2026 [May 27th, 2026]
- How Machine Learning Makes Complex Knowledge Useable in Real-World Conditions - Supply & Demand Chain Executive - May 25th, 2026 [May 25th, 2026]
- How Airbnbs machine-learning tools aim to prevent Memorial Day weekend parties in Las Vegas - FOX5 Vegas - May 25th, 2026 [May 25th, 2026]
- Artificial Intelligence and Machine Learning in Hospital Quality Management, Patient Safety, and Accreditation Readiness: A Systematic Review and... - May 25th, 2026 [May 25th, 2026]
- Machine learning accelerates analysis of fusion materials - Technology Org - May 25th, 2026 [May 25th, 2026]
- Dr. Kaveh Heidary Presents Innovations in AI, Machine Learning and Multispectral Imaging - aamu.edu - May 25th, 2026 [May 25th, 2026]
- Comparison of Prognostic Performance Between a Machine Learning Model and Manually Measured Grey-White-Matter Ratio on Early Brain Computed Tomography... - May 25th, 2026 [May 25th, 2026]
- Machine learning proves that graphene is hydrophobic - Phys.org - May 13th, 2026 [May 13th, 2026]
- Machine learning algorithm predicts AMD stock price on May 31, 2026 - Finbold - May 13th, 2026 [May 13th, 2026]
- Genetic association and machine learning improve the prediction of type 1 diabetes risk - Nature - May 1st, 2026 [May 1st, 2026]
- What Can We Expect From Machine Learning Predictions in Daily Clinical Neurology? - Neurology Live - May 1st, 2026 [May 1st, 2026]
- How Spam Filters Paved the Way for Adversarial Machine Learning - 150sec - May 1st, 2026 [May 1st, 2026]
- Real-Time Estimation of Numerical Rating Scale (NRS) Scores Using Machine Learning-Based Facial Expression Analysis: A Proof-of-Concept Study - Cureus - May 1st, 2026 [May 1st, 2026]
- Heriot-Watt researcher warns gen AI in machine learning carries serious and underestimated risks - EdTech Innovation Hub - May 1st, 2026 [May 1st, 2026]
- HS-SPME/GCMS and Machine Learning Enable Volatile Fingerprinting and Classification of Commercial Vinegars - Chromatography Online - April 12th, 2026 [April 12th, 2026]
- Role of Artificial Intelligence and Machine Learning in Diagnosing Knee Lesions: Where Are We Now? - Cureus - April 12th, 2026 [April 12th, 2026]
- CMML2AML: machine-learning discovery of co-mutations and specific single mutations predictive of blast transformation in chronic myelomonocytic... - April 12th, 2026 [April 12th, 2026]
- Machine-learning-based reconstruction of Ming-dynasty defensive corridors in Yuxian - Nature - April 12th, 2026 [April 12th, 2026]
- Have you published a disruptive paper? New machine-learning tool helps you check - Physics World - April 12th, 2026 [April 12th, 2026]
- Microsoft is automatically updating Windows 11 24H2 to 25H2 using machine learning - TweakTown - April 5th, 2026 [April 5th, 2026]
- Inside the Magic of Machine Learning That Powers Enemy AI in Arc Raiders - 80 Level - April 3rd, 2026 [April 3rd, 2026]
- We analyzed Philly street scenes and identified signs of gentrification using machine learning trained on longtime residents observations - The... - April 3rd, 2026 [April 3rd, 2026]
- Boston University To Apply Machine Learning To Alzheimers Biomarker And Cognitive Data - Quantum Zeitgeist - April 3rd, 2026 [April 3rd, 2026]
- Sony buys machine-learning company to help "enhance gameplay visuals, improve rendering techniques, and unlock new levels of visual... - April 3rd, 2026 [April 3rd, 2026]
- The Machine Learning Stack Is Being Rebuilt From Scratch Here's What Developers Need to Know in 2026 - HackerNoon - April 3rd, 2026 [April 3rd, 2026]
- Closing the Revenue Gap: Leveraging Machine Learning to Solve the $260 Billion Denial Crisis - vocal.media - April 3rd, 2026 [April 3rd, 2026]
- Machine Learning for Pharmaceuticals Set to Witness Rapid - openPR.com - April 3rd, 2026 [April 3rd, 2026]
- You Must Address These 4 Concerns To Deploy Predictive AI - Machine Learning Week US - March 30th, 2026 [March 30th, 2026]
- Google and the rise of space-based machine learning - Latitude Media - March 30th, 2026 [March 30th, 2026]
- Researchers use machine learning and social network theory to identify formation patterns in digital forums - techxplore.com - March 30th, 2026 [March 30th, 2026]
- Mayo Clinic Study Uses Wearables and Machine Learning to Predict COPD Rehab Participation - HIT Consultant - March 30th, 2026 [March 30th, 2026]
- Machine learning at the edge in retail: constraints and gains - IoT News - March 26th, 2026 [March 26th, 2026]
- AI agents are flashy, but machine learning still pays the bills - TechRadar - March 26th, 2026 [March 26th, 2026]
- Single-cell imaging and machine learning reveal hidden coordination in algae's response to light stress - Phys.org - March 26th, 2026 [March 26th, 2026]
- Machine learning analysis of CT scans - National Institutes of Health (.gov) - March 22nd, 2026 [March 22nd, 2026]
- TransUnion Machine Learning Fraud Tools Tested Against Weak Share Price Momentum - simplywall.st - March 22nd, 2026 [March 22nd, 2026]
- Machine learning could help predict how people with depression respond to treatment - Medical Xpress - March 22nd, 2026 [March 22nd, 2026]
- KR approves machine learning-based fuel reduction methodology - Smart Maritime Network - March 22nd, 2026 [March 22nd, 2026]
- Available solar energy in Andalusia will increase through the end of the century, machine learning model finds - Tech Xplore - March 22nd, 2026 [March 22nd, 2026]
- How Machine Learning Is Reshaping Environmental Policy and Water Governance - Devdiscourse - March 22nd, 2026 [March 22nd, 2026]
- Chemistry student uses machine learning to transform gene therapy production - The University of North Carolina at Chapel Hill - March 13th, 2026 [March 13th, 2026]
- AI and Machine Learning - City of Brownsville to build smart city safety solution - Smart Cities World - March 13th, 2026 [March 13th, 2026]
- AI and Machine Learning - London borough overhauls public safety infrastructure - Smart Cities World - March 13th, 2026 [March 13th, 2026]
- Titan Technology Corp. Responds to Alberta Innovates RFP AI, Machine Learning and Automation Services - TradingView - March 13th, 2026 [March 13th, 2026]
- Vietnam FPT's AI automation solution secures new machine learning patent on overseas market - VnExpress International - March 13th, 2026 [March 13th, 2026]
- AI Healthcare Technology: The Power of Machine Learning Diagnosis in Modern Medicine - Tech Times - March 13th, 2026 [March 13th, 2026]
- Future Perspectives: Key Trends Shaping the Machine Learning Market in Financial Services Until 2030 - openPR.com - March 13th, 2026 [March 13th, 2026]
- How to Build an Autonomous Machine Learning Research Loop in Google Colab Using Andrej Karpathys AutoResearch Framework for Hyperparameter Discovery... - March 13th, 2026 [March 13th, 2026]