Skip to content

Commit

Permalink
Merge pull request #32 from the-database/dev
Browse files Browse the repository at this point in the history
#11 multiple dots #19 no model #20 console button cuttoff, grayscale performance improvements
  • Loading branch information
the-database authored Jul 31, 2024
2 parents 0b1d692 + eec0948 commit 5b839cd
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 72 deletions.
2 changes: 2 additions & 0 deletions MangaJaNaiConverterGui/Services/PythonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public AvaloniaList<string> AllModels
.Select(filename => Path.GetFileName(filename))
.Order().ToList());

models.Add("No Model");

Debug.WriteLine($"GetAllModels: {models.Count}");

_allModels = models;
Expand Down
26 changes: 9 additions & 17 deletions MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,11 +816,9 @@ public void CheckInputs()

if (IMAGE_EXTENSIONS.Any(x => CurrentWorkflow.InputFilePath.ToLower().EndsWith(x)))
{
var outputFilePath = Path.ChangeExtension(
Path.Join(
var outputFilePath = Path.Join(
Path.GetFullPath(CurrentWorkflow.OutputFolderPath),
CurrentWorkflow.OutputFilename.Replace("%filename%", Path.GetFileNameWithoutExtension(CurrentWorkflow.InputFilePath))),
CurrentWorkflow.ImageFormat);
CurrentWorkflow.OutputFilename.Replace("%filename%", Path.GetFileNameWithoutExtension(CurrentWorkflow.InputFilePath))) + $".{CurrentWorkflow.ImageFormat}";
if (File.Exists(outputFilePath))
{
status.Append($" (1 image already exists and will be {overwriteText})");
Expand All @@ -832,11 +830,9 @@ public void CheckInputs()
}
else if (ARCHIVE_EXTENSIONS.Any(x => CurrentWorkflow.InputFilePath.ToLower().EndsWith(x)))
{
var outputFilePath = Path.ChangeExtension(
Path.Join(
Path.GetFullPath(CurrentWorkflow.OutputFolderPath),
CurrentWorkflow.OutputFilename.Replace("%filename%", Path.GetFileNameWithoutExtension(CurrentWorkflow.InputFilePath))),
"cbz");
var outputFilePath = Path.Join(Path.GetFullPath(CurrentWorkflow.OutputFolderPath),
CurrentWorkflow.OutputFilename.Replace("%filename%", Path.GetFileNameWithoutExtension(CurrentWorkflow.InputFilePath))) + ".cbz";

if (File.Exists(outputFilePath))
{
status.Append($" (1 archive already exists and will be {overwriteText})");
Expand Down Expand Up @@ -887,11 +883,9 @@ public void CheckInputs()

foreach (var inputImagePath in images)
{
var outputImagePath = Path.ChangeExtension(
Path.Join(
var outputImagePath = Path.Join(
Path.GetFullPath(CurrentWorkflow.OutputFolderPath),
CurrentWorkflow.OutputFilename.Replace("%filename%", Path.GetFileNameWithoutExtension(inputImagePath))),
CurrentWorkflow.ImageFormat);
CurrentWorkflow.OutputFilename.Replace("%filename%", Path.GetFileNameWithoutExtension(inputImagePath))) + $"{CurrentWorkflow.ImageFormat}";
// if out file exists, exist count ++
// if overwrite image OR out file doesn't exist, count image++
var fileExists = File.Exists(outputImagePath);
Expand Down Expand Up @@ -921,11 +915,9 @@ public void CheckInputs()

foreach (var inputArchivePath in archives)
{
var outputArchivePath = Path.ChangeExtension(
Path.Join(
var outputArchivePath = Path.Join(
Path.GetFullPath(CurrentWorkflow.OutputFolderPath),
CurrentWorkflow.OutputFilename.Replace("%filename%", Path.GetFileNameWithoutExtension(inputArchivePath))),
"cbz");
CurrentWorkflow.OutputFilename.Replace("%filename%", Path.GetFileNameWithoutExtension(inputArchivePath))) + ".cbz";
var fileExists = File.Exists(outputArchivePath);

if (fileExists)
Expand Down
18 changes: 12 additions & 6 deletions MangaJaNaiConverterGui/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,16 @@

<DockPanel Margin="0" Height="30" DockPanel.Dock="Bottom" HorizontalAlignment="Stretch">

<TextBlock Margin="10,10,10,0" DockPanel.Dock="Left" FontSize="10" Text="{Binding LeftStatus}" />
<TextBlock Margin="10,10,10,0" DockPanel.Dock="Left" FontSize="10" Text="{Binding LeftStatus}" VerticalAlignment="Center" />
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal">

<StackPanel Orientation="Horizontal" IsVisible="{Binding ShowEstimates}">
<TextBlock TextAlignment="Center" Width="140" FontSize="10" Margin="10,10,20,0" Text="{Binding ElapsedTime, StringFormat={}Elapsed Time: {0}}" />
<TextBlock TextAlignment="Center" Width="140" FontSize="10" Margin="5,10,10,0" Text="{Binding ElapsedTime, StringFormat={}Elapsed Time: {0}}" />
<StackPanel Orientation="Horizontal" IsVisible="{Binding ShowArchiveProgressBar}">
<TextBlock TextAlignment="Center" Width="220" FontSize="10" Margin="10,10,20,0" Text="{Binding ArchiveEtr, StringFormat=Remaining Time (Current Archive): {0:hh\\:mm\\:ss}}" />
<TextBlock TextAlignment="Center" Width="220" FontSize="10" Margin="5,10,10,0" Text="{Binding ArchiveEtr, StringFormat=Remaining Time (Current Archive): {0:hh\\:mm\\:ss}}" />
</StackPanel>
<TextBlock TextAlignment="Center" Width="180" FontSize="10" Margin="10,10,20,0" Text="{Binding TotalEtr, StringFormat=Remaining Time (Total): {0:hh\\:mm\\:ss}}" />
<TextBlock TextAlignment="Center" Width="180" FontSize="10" Margin="10,10,20,0" Text="{Binding TotalEta, StringFormat={}Estimated Finish Time: {0}}" />
<TextBlock TextAlignment="Center" Width="180" FontSize="10" Margin="5,10,10,0" Text="{Binding TotalEtr, StringFormat=Remaining Time (Total): {0:hh\\:mm\\:ss}}" />
<TextBlock TextAlignment="Center" Width="180" FontSize="10" Margin="5,10,10,0" Text="{Binding TotalEta, StringFormat={}Estimated Finish Time: {0}}" />
</StackPanel>

<!-- progress within current archive -->
Expand All @@ -163,6 +163,9 @@
ProgressTextFormat="{}{0:0} / {3:0} images in current archive"
FontSize="10"
ShowProgressText="True"
MinWidth="50"
Width="50"
MaxWidth="50"
IsVisible="{Binding ShowArchiveProgressBar}" />

<!-- total progress across all files -->
Expand All @@ -172,6 +175,9 @@
Value="{Binding ProgressCurrentFile}"
ProgressTextFormat="{}{0:0} / {3:0} total files"
FontSize="10"
MinWidth="50"
Width="50"
MaxWidth="50"
ShowProgressText="True"/>

<ToggleButton IsChecked="{Binding ShowConsole}" FontSize="10" Margin="5,0,5,0">
Expand Down Expand Up @@ -536,7 +542,7 @@
<TextBlock Margin="5,0,0,0" Text="Open Models Directory" />
</StackPanel>
</Button>
<TextBlock Foreground="Gray" FontSize="12" VerticalAlignment="Center" Margin="20,0,0,0">The upscaling model to run. To choose from more models, add PyTorch (*.pth) model files to the models directory.</TextBlock>
<TextBlock Width="500" TextWrapping="WrapWithOverflow" Foreground="Gray" FontSize="12" VerticalAlignment="Center" Margin="20,0,0,0">The upscaling model to run. To choose from more models, add PyTorch (*.pth) model files to the models directory. Select No Model to skip running any upscaling model for this chain.</TextBlock>
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="10,0,0,10">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,23 @@ def upscale(img: np.ndarray, _: object):
try:
# convert to tensor
input_tensor = _into_tensor(img, device, dtype)
input_tensor = _rgb_to_bgr(input_tensor)
# expand grayscale tensor to match model input channels
input_ndim = input_tensor.ndim
if input_ndim == 2 and model.input_channels > 1:
input_tensor = input_tensor.unsqueeze(-1).repeat(1, 1, model.input_channels)
else:
input_tensor = _rgb_to_bgr(input_tensor)
input_tensor = _into_batched_form(input_tensor)

# inference
output_tensor = model(input_tensor)

# convert back to numpy
output_tensor = _into_standard_image_form(output_tensor)
output_tensor = _rgb_to_bgr(output_tensor)
if input_ndim == 2:
output_tensor = output_tensor[..., 0]
else:
output_tensor = _rgb_to_bgr(output_tensor)
result = output_tensor.detach().cpu().detach().float().numpy()

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def convenient_upscale(

return np.dstack((black_up, alpha))

# skip all conversions for grayscale to improve performance by reducing the amount of data that needs to be copied
# instead we do the color conversions on the tensors after they're already on the gpu
if in_img_c == 1:
return upscale(img)

return as_target_channels(
upscale(as_target_channels(img, model_in_nc, True)), in_img_c, True
)
Loading

0 comments on commit 5b839cd

Please sign in to comment.