Skip to content

Commit

Permalink
新增 模型大小显示
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Feb 6, 2025
1 parent bc01c83 commit 17db050
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections;
using System.IO;
using Core.SDKs.Services.Plugin;
using PluginCore.Onnx;

namespace KitopiaAvalonia.Converter.OnnxModelManagerPage;

public class DataGridModelSizeComparer : IComparer
{
public static readonly DataGridModelSizeComparer Default = new DataGridModelSizeComparer();

public int Compare(object? x, object? y)
{
if (x is OnnxModelInfoWrapper onnxModelInfoWrapper &&y is OnnxModelInfoWrapper onnxModelInfoWrapper2)
{
var path = PluginManager.GetPluginByPlgStr(onnxModelInfoWrapper.PluginStr).Path;
var fileInfo = new FileInfo($"{path}{onnxModelInfoWrapper.Model.ModelPath}");
var path2 = PluginManager.GetPluginByPlgStr(onnxModelInfoWrapper2.PluginStr).Path;
var fileInfo2 = new FileInfo($"{path2}{onnxModelInfoWrapper2.Model.ModelPath}");
if (fileInfo.Length> fileInfo2.Length)
{
return 1;
}

if (fileInfo.Length < fileInfo2.Length)
{
return -1;
}
}

return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Globalization;
using System.IO;
using Avalonia.Data.Converters;
using Core.SDKs.Services.Plugin;
using PluginCore.Onnx;

namespace KitopiaAvalonia.Converter.OnnxModelManagerPage;

public class OnnxModelInfoWrapperToModelSizeCtr : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is OnnxModelInfoWrapper onnxModelInfoWrapper)
{
var path = PluginManager.GetPluginByPlgStr(onnxModelInfoWrapper.PluginStr).Path;
var fileInfo = new FileInfo($"{path}{onnxModelInfoWrapper.Model.ModelPath}");
if (fileInfo.Exists)
{
if (fileInfo.Length>1024*1024 * 1024)
{
return $"{Math.Round((double)fileInfo.Length / (1024 * 1024 * 1024), 2)}GB";
}else if (fileInfo.Length > 1024 * 1024)
{
return $"{Math.Round((double)fileInfo.Length / (1024 * 1024), 2)}MB";
}
else
{
return $"{Math.Round((double)fileInfo.Length / 1024, 2)}KB";
}

}
}

return "0B";
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return null;
}
}
5 changes: 5 additions & 0 deletions KitopiaAvalonia/Pages/OnnxModelManagerPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<pluginManagerPage1:IconCtr x:Key="IconCtr" />
<onnxModelManagerPage:ModelInfoToRuntimeChangerCtr x:Key="ModelInfoToRuntimeChangerCtr" />
<onnxModelManagerPage:OnnxModelInfoWrapperToHelper x:Key="OnnxModelInfoWrapperToHelper" />
<onnxModelManagerPage:OnnxModelInfoWrapperToModelSizeCtr x:Key="OnnxModelInfoWrapperToModelSizeCtr" />
</UserControl.Resources>
<Panel>
<ContentPresenter ZIndex="1" x:Name="DialogOvercover" />
Expand Down Expand Up @@ -100,6 +101,10 @@

</DataTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="模型大小" Binding="{Binding Converter={StaticResource OnnxModelInfoWrapperToModelSizeCtr} }"
CanUserReorder="True" CanUserSort="True" CustomSortComparer="{x:Static onnxModelManagerPage:DataGridModelSizeComparer.Default }">

</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>

Expand Down

0 comments on commit 17db050

Please sign in to comment.