Giter VIP home page Giter VIP logo

Comments (2)

StealUrKill avatar StealUrKill commented on August 18, 2024 2

I have created a gui but it still requires python to be installed with all the supporting extras. This works with cuda, tensor, openvino, cpu, and dml execution providers. OpenVino is harder to get going as I cant seem to make it work with the pip module and have to use the zip located https://docs.openvino.ai/2023.3/openvino_docs_install_guides_installing_openvino_from_archive_windows.html

And then specifically tell it to use the setupvars.bat that comes with the zip. Also it seems the onnxruntime for openvino 1.17.1 does not work as there is entry point errors in the capi dll but 1.16.0 works fine.

image

This is some of the code that is in place for the GUI. Now I have also forked this and added extra options to the Deface tool.

using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections.Generic;


namespace AnonFacesApp
{
    public partial class MainForm : Form
    {
        private Process runningProcess;
        private bool isProcessRunning;
        private string lastSelectedFile;
        private string ExecutionProvider;
        private readonly string CudaDirectory = @"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA";
        private readonly string TensorDirectory = @"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA";
        private readonly string NvinferDllPath = "lib\\nvinfer.dll";
        private const string KeepAudioOption = "--keep-audio";
        private const string ViewPreviewOption = "--preview";
        private const string ScaleOption = "--scale 1280x720";
        private const string DistortAudio = "--distort-audio";
        private const string rootDirectory = @"C:\Program Files (x86)\Intel";
        private decimal thresh = 0.200M;
        private Process ffmpegProcess;


        public MainForm()
        {
            InitializeComponent();
            this.AllowDrop = true;
            this.Load += MainForm_Load;
            AudioCheckBox.Checked = true;
            trackBar1.Scroll += TrackBar1_Scroll;
        }


        private void MainForm_Load(object sender, EventArgs e)
        {
            // In the MainForm_Load event, set the TrackBar properties:
            trackBar1.Minimum = 0;
            trackBar1.Maximum = 12; // 10 steps (0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.20, 0.22)
            trackBar1.LargeChange = 1;
            trackBar1.SmallChange = 1;
            trackBar1.TickFrequency = 1;
            trackBar1.Value = 9; // 0.200 corresponds to the midddle step
            UpdateLabelFromTrackBarValue(); // Update the label to reflect the default value.
            List<string> availableProviders = GetAvailableProviders();
            // Populate the ComboBox with the obtained providers
            ExecutionComboBox.Items.AddRange(availableProviders.ToArray());

            // Check if OpenVINO or CUDA are available
            if (availableProviders.Contains("OpenVINOExecutionProvider"))
            {
                ExecutionComboBox.SelectedItem = "OpenVINOExecutionProvider";
                SetExecutionProviderFromComboBox();
            }
            else if (availableProviders.Contains("CUDAExecutionProvider"))
            {
                ExecutionComboBox.SelectedItem = "CUDAExecutionProvider";
                SetExecutionProviderFromComboBox();
            }
            else if (availableProviders.Contains("DmlExecutionProvider"))
            {
                ExecutionComboBox.SelectedItem = "DmlExecutionProvider";
                SetExecutionProviderFromComboBox();
            }
            else
            {
                // If neither provider is available, you can set a default selection
                ExecutionComboBox.SelectedItem = "CPUExecutionProvider";
                SetExecutionProviderFromComboBox();
            }
        }

        private List<string> ParseAvailableProviders(string providersString)
        {
            List<string> availableProviders = new List<string>();

            string[] providerArray = providersString
                .Replace("[", "")
                .Replace("]", "")
                .Replace("'", "")
                .Split(',')
                .Select(provider => provider.Trim())
                .ToArray();

            availableProviders.AddRange(providerArray);

            return availableProviders;
        }

        private List<string> GetAvailableProviders()
        {
            try
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process
                {
                    StartInfo = new System.Diagnostics.ProcessStartInfo
                    {
                        FileName = "python",
                        RedirectStandardOutput = true,
                        UseShellExecute = false,
                        CreateNoWindow = true,
                        Arguments = "-c \"import onnx; import onnxruntime; print(onnxruntime.get_available_providers())\""
                    }
                };

                process.Start();
                string providersString = process.StandardOutput.ReadToEnd();

                return ParseAvailableProviders(providersString);
            }
            catch (Exception)
            {
                // Handle the exception if needed
                return new List<string>();
            }
        }



        private void SetExecutionProviderFromComboBox()
        {
            int selectedProviderIndex = ExecutionComboBox.SelectedIndex;

            // Get the list of available providers dynamically
            List<string> availableProviders = GetAvailableProviders();

            if (selectedProviderIndex >= 0 && selectedProviderIndex < availableProviders.Count)
            {
                // Set the execution provider based on the selected index
                string selectedProvider = availableProviders[selectedProviderIndex];

                // Implement logic based on the selected provider
                switch (selectedProvider)
                {
                    case "DmlExecutionProvider":
                        ExecutionProvider = "--ep DmlExecutionProvider";
                        break;

                    case "CPUExecutionProvider":
                        ExecutionProvider = "--ep CPUExecutionProvider";
                        break;

                    case "CUDAExecutionProvider":
                        ExecutionProvider = "--ep CUDAExecutionProvider";
                        break;

                    case "TensorrtExecutionProvider":
                        ExecutionProvider = "--ep TensorrtExecutionProvider";
                        break;

                    case "OpenVINOExecutionProvider":
                        ExecutionProvider = "--ep OpenVINOExecutionProvider";
                        break;

                    default:
                        // Handle the default case (e.g., show an error message)
                        MessageBox.Show("Invalid selection");
                        break;
                }
            }
            else
            {
                // Handle the case where the selected index is out of bounds
                MessageBox.Show("Invalid selection");
            }
        }```



from deface.

StealUrKill avatar StealUrKill commented on August 18, 2024

I have created a gui but it still requires python to be installed with all the supporting extras. This works with cuda, tensor, openvino, cpu, and dml execution providers. OpenVino is harder to get going as I cant seem to make it work with the pip module and have to use the zip located https://docs.openvino.ai/2023.3/openvino_docs_install_guides_installing_openvino_from_archive_windows.html

And then specifically tell it to use the setupvars.bat that comes with the zip. Also it seems the onnxruntime for openvino 1.17.1 does not work as there is entry point errors in the capi dll but 1.16.0 works fine.

Seems like the issue with 1.17.1 was my Python Version. I thought i had 3.11.9 but the instance was confused on the multiple versions on my machine. So this works lol

from deface.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.