/// <summary> /// NeuralStyleTransformerDescriptor constructor /// </summary> public NeuralStyleTransformerDescriptor(StyleChoices styleChoice = StyleChoices.Candy) { Name = "NeuralStyleTransformer"; Description = "Transform your image to an art"; // {F8D275CE-C244-4E71-8A39-57335D291387} Id = new Guid(0xf8d275ce, 0xc244, 0x4e71, 0x8a, 0x39, 0x57, 0x33, 0x5d, 0x29, 0x13, 0x87); Version = SkillVersion.Create( 0, // major version 1, // minor version "Makers ID", // Author name "Buitenzorg Makers Club" // Publisher name ); // Describe input feature m_inputSkillDesc = new List <ISkillFeatureDescriptor>(); m_inputSkillDesc.Add( new SkillFeatureImageDescriptor( NeuralStyleTransformerConst.SKILL_INPUTNAME_IMAGE, "the input image onto which the model runs", true, // isRequired (since this is an input, it is required to be bound before the evaluation occurs) -1, // width -1, // height -1, // maxDimension BitmapPixelFormat.Nv12, BitmapAlphaMode.Ignore) ); // Describe first output feature m_outputSkillDesc = new List <ISkillFeatureDescriptor>(); m_outputSkillDesc.Add( new SkillFeatureImageDescriptor( NeuralStyleTransformerConst.SKILL_OUTPUTNAME_IMAGE, "a transformed image", true, // isRequired -1, // width -1, // height -1, // maxDimension BitmapPixelFormat.Nv12, BitmapAlphaMode.Ignore) ); //default this.styleChoice = styleChoice; }
/// <summary> /// Creates and initializes a NeuralStyleTransformerSkill instance /// </summary> /// <param name="descriptor"></param> /// <param name="device"></param> /// <returns></returns> internal static IAsyncOperation <NeuralStyleTransformerSkill> CreateAsync( ISkillDescriptor descriptor, ISkillExecutionDevice device, StyleChoices Mode) { return(AsyncInfo.Run(async(token) => { // Create instance var skillInstance = new NeuralStyleTransformerSkill(descriptor, device); // Load WinML model var modelName = "candy.onnx"; switch (Mode) { case StyleChoices.Candy: modelName = "candy.onnx"; break; case StyleChoices.Mosaic: modelName = "mosaic.onnx"; break; case StyleChoices.Pointilism: modelName = "pointilism.onnx"; break; case StyleChoices.RainPrincess: modelName = "rain_princess.onnx"; break; case StyleChoices.Udnie: modelName = "udnie.onnx"; break; } var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///NeuralStyleTransformer/Models/{modelName}")); var winmlModel = LearningModel.LoadFromFilePath(modelFile.Path); // Create WinML session skillInstance.m_winmlSession = new LearningModelSession(winmlModel, GetWinMLDevice(device)); // Create output frame _outputFrame?.Dispose(); _outputFrame = new VideoFrame(BitmapPixelFormat.Bgra8, NeuralStyleTransformerConst.IMAGE_WIDTH, NeuralStyleTransformerConst.IMAGE_HEIGHT); return skillInstance; })); }
public void SetStyle(StyleChoices styleChoice) { this.styleChoice = styleChoice; }