Skip to content

Commit

Permalink
rework build system and make preview better
Browse files Browse the repository at this point in the history
  • Loading branch information
TNTwise committed Nov 4, 2024
1 parent ddec64b commit dcb1726
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 23 deletions.
4 changes: 2 additions & 2 deletions backend/src/InterpolateTorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def _load(self):
printAndLog(
f"Loading TensorRT engine from {encode_trt_engine_path}"
)
self.encode = torch.jit.load(encode_trt_engine_path).eval()
self.encode = trtHandler.load_engine(encode_trt_engine_path)

# export flow engine
printAndLog(
Expand All @@ -404,7 +404,7 @@ def _load(self):
trtHandler.build_engine(model=self.flownet,dtype=self.dtype,example_inputs=exampleInput,device=self.device,trt_engine_path=trt_engine_path)

printAndLog(f"Loading TensorRT engine from {trt_engine_path}")
self.flownet = torch.jit.load(trt_engine_path).eval()
self.flownet = trtHandler.load_engine(trt_engine_path)
self.prepareStream.synchronize()

@torch.inference_mode()
Expand Down
3 changes: 3 additions & 0 deletions backend/src/TensorRTHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ def build_engine(
output_format="torchscript",
inputs=tuple(example_inputs),
)

def load_engine(self, trt_engine_path: str):
return torch.jit.load(trt_engine_path).eval()
11 changes: 7 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,19 @@ def checkIfExeExists(exe):
return path is not None


install_pip()

linux_and_mac_py_ver = "python3.10"
python_version = (
linux_and_mac_py_ver
if getPlatform() != "win32" and checkIfExeExists(linux_and_mac_py_ver)
else "python3"
)
create_venv(python_version=python_version)
install_pip_in_venv()
install_requirements_in_venv()
if len(sys.argv) > 1:
if sys.argv[1] == "--create_venv" or sys.argv[1] == "--build_exe":
install_pip()
create_venv(python_version=python_version)
install_pip_in_venv()
install_requirements_in_venv()
build_gui()
build_resources()
if len(sys.argv) > 1:
Expand Down
2 changes: 2 additions & 0 deletions src/Backendhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def getAvailableBackends(self):
output = SettingUpBackendPopup(
[
pythonPath(),
"-W",
"ignore",
os.path.join(backendDirectory(), "rve-backend.py"),
"--list_backends",
]
Expand Down
31 changes: 29 additions & 2 deletions src/ui/ProcessTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import re

from PySide6 import QtGui
from PySide6.QtGui import QPixmap, QPainter, QPainterPath
from PySide6.QtCore import Qt
from PySide6.QtGui import QPixmap, QPainter, QPainterPath, QColor
from PySide6.QtCore import Qt, QSize
from ..BuildFFmpegCommand import BuildFFMpegCommand

from .AnimationHandler import AnimationHandler
Expand Down Expand Up @@ -392,6 +392,23 @@ def renderToPipeThread(self, method: str, backend: str, interpolateTimes: int):

self.parent.onRenderCompletion()


def pad_pixmap(self, original_pixmap, width, height, background_color=QColor(255, 255, 255, 0)):
# Create a new QPixmap with the desired dimensions
padded_pixmap = QPixmap(width, height)
padded_pixmap.fill(background_color)

# Calculate the position to center the original pixmap
x = (width - original_pixmap.width()) // 2
y = (height - original_pixmap.height()) // 2

# Draw the original pixmap onto the new pixmap
painter = QPainter(padded_pixmap)
painter.drawPixmap(x, y, original_pixmap)
painter.end()

return padded_pixmap

def getRoundedPixmap(self, pixmap, corner_radius):
size = pixmap.size()
mask = QPixmap(size)
Expand Down Expand Up @@ -444,4 +461,14 @@ def updateProcessTab(self, qimage: QtGui.QImage):
p = qimage.scaled(width / 2, height / 2, Qt.AspectRatioMode.KeepAspectRatio) # type: ignore
pixmap = QtGui.QPixmap.fromImage(p)
roundedPixmap = self.getRoundedPixmap(pixmap, corner_radius=10)
padding = 20 # Amount of padding on each side
label_width = self.parent.previewLabel.width()
label_height = self.parent.previewLabel.height()
padded_width = label_width - 2 * padding
padded_height = label_height - 2 * padding

# Ensure the padded dimensions are not smaller than the original pixmap
padded_width = max(padded_width, roundedPixmap.width())
padded_height = max(padded_height, roundedPixmap.height())
roundedPixmap = self.pad_pixmap(roundedPixmap, padded_width, padded_height)
self.parent.previewLabel.setPixmap(roundedPixmap)
80 changes: 65 additions & 15 deletions testRVEInterface.ui
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ QDoubleSpinBox::down-button {
<rect>
<x>0</x>
<y>0</y>
<width>378</width>
<height>426</height>
<width>366</width>
<height>452</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -963,13 +963,13 @@ p, li { white-space: pre-wrap; }
hr { height: 1px; border-width: 0; }
li.unchecked::marker { content: &quot;\2610&quot;; }
li.checked::marker { content: &quot;\2612&quot;; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;FPS:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Resolution:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Bitrate:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Encoder:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Container:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Frame Count:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif';&quot;&gt;FPS:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif';&quot;&gt;Resolution:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif';&quot;&gt;Bitrate:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif';&quot;&gt;Encoder:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif';&quot;&gt;Container:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif';&quot;&gt;Frame Count:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1140,9 +1140,39 @@ border-radius: 10px;
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>9</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QWidget" name="previewSubContainer" native="true">
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="previewLabel">
<property name="sizePolicy">
Expand All @@ -1152,13 +1182,18 @@ border-radius: 10px;
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
<string notr="true">
QLabel{
color: #fff;
background-color:#1f232a;
}
</string>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
Expand All @@ -1168,6 +1203,21 @@ border-radius: 10px;
<item>
<widget class="QWidget" name="infoSubContainer" native="true">
<layout class="QVBoxLayout" name="verticalLayout_9">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTextEdit" name="renderOutput">
<property name="sizePolicy">
Expand Down Expand Up @@ -1197,8 +1247,8 @@ p, li { white-space: pre-wrap; }
hr { height: 1px; border-width: 0; }
li.unchecked::marker { content: &quot;\2610&quot;; }
li.checked::marker { content: &quot;\2612&quot;; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:15pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:15pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1313,8 +1363,8 @@ QDoubleSpinBox::down-button {
<rect>
<x>0</x>
<y>0</y>
<width>755</width>
<height>676</height>
<width>466</width>
<height>616</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
Expand Down

0 comments on commit dcb1726

Please sign in to comment.