opt import module and cupy
This commit is contained in:
parent
b187e36aa4
commit
c926bc0072
@ -1,10 +1,11 @@
|
|||||||
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import tomllib
|
import tomllib
|
||||||
from enum import Enum
|
from enum import Enum, auto
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import click
|
import click
|
||||||
@ -14,39 +15,24 @@ from flandre import C
|
|||||||
from flandre import P
|
from flandre import P
|
||||||
from flandre.BusClient import BusClient
|
from flandre.BusClient import BusClient
|
||||||
from flandre.kde_pyqt6_mainui import kde_pyqt6_mainui
|
from flandre.kde_pyqt6_mainui import kde_pyqt6_mainui
|
||||||
from flandre.nodes.Beamformer import Beamformer
|
|
||||||
from flandre.nodes.Broker import Broker
|
from flandre.nodes.Broker import Broker
|
||||||
from flandre.nodes.Device import Device
|
|
||||||
from flandre.nodes.ImageCV import ImageCV
|
|
||||||
from flandre.nodes.ImageFFMPEG import ImageFFMPEG
|
|
||||||
from flandre.nodes.ImageQt import ImageQt
|
|
||||||
from flandre.nodes.Loader import Loader
|
|
||||||
from flandre.nodes.MainUI import MainUI
|
|
||||||
from flandre.nodes.Mi import Mi
|
|
||||||
from flandre.nodes.Midi import Midi
|
|
||||||
from flandre.nodes.Muxer import Muxer
|
|
||||||
from flandre.nodes.Recorder import Recorder
|
|
||||||
from flandre.nodes.Robot import Robot
|
|
||||||
from flandre.nodes.VideoQt import VideoQt
|
|
||||||
from flandre.nodes.Web import Web
|
|
||||||
from flandre.utils.Msg import KillMsg, NodeOnlineMsg, Msg1, Msg2
|
from flandre.utils.Msg import KillMsg, NodeOnlineMsg, Msg1, Msg2
|
||||||
|
|
||||||
|
|
||||||
class LaunchComponent(Enum):
|
class LaunchComponent(Enum):
|
||||||
MainUI = MainUI
|
MainUI = auto()
|
||||||
ImageCV = ImageCV
|
ImageCV = auto()
|
||||||
Muxer = Muxer
|
Muxer = auto()
|
||||||
Robot = Robot
|
Robot = auto()
|
||||||
Loader = Loader
|
Loader = auto()
|
||||||
Device = Device
|
Device = auto()
|
||||||
Recorder = Recorder
|
Recorder = auto()
|
||||||
Beamformer = Beamformer
|
Beamformer = auto()
|
||||||
ImageFFMPEG = ImageFFMPEG
|
ImageFFMPEG = auto()
|
||||||
ImageQt = ImageQt
|
ImageQt = auto()
|
||||||
Midi = Midi
|
Midi = auto()
|
||||||
Mi = Mi
|
Mi = auto()
|
||||||
Web = Web
|
Web = auto()
|
||||||
VideoQt = VideoQt
|
VideoQt = auto()
|
||||||
|
|
||||||
|
|
||||||
def launch(arg: dict[LaunchComponent, dict]):
|
def launch(arg: dict[LaunchComponent, dict]):
|
||||||
@ -59,7 +45,9 @@ def launch(arg: dict[LaunchComponent, dict]):
|
|||||||
if k == LaunchComponent.MainUI and os.environ.get('XDG_CURRENT_DESKTOP', None) == 'KDE':
|
if k == LaunchComponent.MainUI and os.environ.get('XDG_CURRENT_DESKTOP', None) == 'KDE':
|
||||||
ps.append(kde_pyqt6_mainui)
|
ps.append(kde_pyqt6_mainui)
|
||||||
continue
|
continue
|
||||||
ps.append(k.value(**v))
|
m = importlib.import_module(f"flandre.nodes.{k.name}")
|
||||||
|
c = getattr(m, k.name)
|
||||||
|
ps.append(c(**v))
|
||||||
|
|
||||||
pps = []
|
pps = []
|
||||||
for p in ps:
|
for p in ps:
|
||||||
|
|||||||
@ -1,17 +1,13 @@
|
|||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
|
|
||||||
import cv2
|
|
||||||
import numpy as np
|
|
||||||
from PyQt6.QtCore import QByteArray, Qt
|
from PyQt6.QtCore import QByteArray, Qt
|
||||||
from PyQt6.QtGui import QImage, QPixmap, QKeyEvent, QWheelEvent
|
from PyQt6.QtGui import QImage, QPixmap, QKeyEvent, QWheelEvent
|
||||||
from PyQt6.QtWidgets import QMainWindow, QApplication, QGraphicsPixmapItem, QGraphicsScene
|
from PyQt6.QtWidgets import QMainWindow, QApplication, QGraphicsPixmapItem, QGraphicsScene
|
||||||
|
|
||||||
from flandre import C
|
|
||||||
from flandre.nodes.Node import Node
|
from flandre.nodes.Node import Node
|
||||||
from flandre.pyqt.Image import Ui_MainWindow
|
from flandre.pyqt.Image import Ui_MainWindow
|
||||||
from flandre.pyqt.ZMQReceiver import ZMQReceiver
|
from flandre.pyqt.ZMQReceiver import ZMQReceiver
|
||||||
from flandre.utils.Msg import KillMsg, Msg, BMMsg, RfMatMsg, KeyPressMsg, RGB888Msg
|
from flandre.utils.Msg import KillMsg, Msg, BMMsg, RfMatMsg, KeyPressMsg
|
||||||
from flandre.utils.RfMat import RfMat
|
from flandre.utils.RfMat import RfMat
|
||||||
|
|
||||||
|
|
||||||
@ -79,38 +75,6 @@ class Adv(QMainWindow, Ui_MainWindow):
|
|||||||
if self.need_fit:
|
if self.need_fit:
|
||||||
self.graphicsView.fitInView(self.s.sceneRect(), Qt.AspectRatioMode.KeepAspectRatio)
|
self.graphicsView.fitInView(self.s.sceneRect(), Qt.AspectRatioMode.KeepAspectRatio)
|
||||||
self.need_fit = False
|
self.need_fit = False
|
||||||
# elif isinstance(msg, RGB888Msg):
|
|
||||||
# w = msg.w
|
|
||||||
# h = msg.h
|
|
||||||
# d: RfMat = msg.rfmat
|
|
||||||
# d2 = (d
|
|
||||||
# .resize((int(w * self.zoom), int(h * self.zoom)))
|
|
||||||
# .watermark(cond=self.watermark)
|
|
||||||
# )
|
|
||||||
# w = d2.w
|
|
||||||
# h = d2.h
|
|
||||||
# if self.grey:
|
|
||||||
# qImg = QImage(
|
|
||||||
# d2.__bytes__(),
|
|
||||||
# w, h, w,
|
|
||||||
# QImage.Format.Format_Grayscale8
|
|
||||||
# )
|
|
||||||
# else:
|
|
||||||
# qImg = QImage(
|
|
||||||
# d2.__bytes__(),
|
|
||||||
# w, h, 3 * w,
|
|
||||||
# QImage.Format.Format_BGR888
|
|
||||||
# )
|
|
||||||
# self.g.setPixmap(QPixmap(qImg))
|
|
||||||
# self.s.setSceneRect(0.0, 0.0, w, h)
|
|
||||||
# if self.scale:
|
|
||||||
# self.graphicsView.fitInView(self.s.sceneRect())
|
|
||||||
# else:
|
|
||||||
# if self.need_fit:
|
|
||||||
# self.graphicsView.fitInView(self.s.sceneRect(), Qt.AspectRatioMode.KeepAspectRatio)
|
|
||||||
# self.need_fit = False
|
|
||||||
#
|
|
||||||
# RGB888Msg
|
|
||||||
|
|
||||||
|
|
||||||
class ImageQt(Node):
|
class ImageQt(Node):
|
||||||
|
|||||||
@ -1,20 +1,12 @@
|
|||||||
import inspect
|
import inspect
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import cupyx
|
|
||||||
import cv2
|
|
||||||
import matplotlib
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cupy as cp
|
|
||||||
|
|
||||||
import cupyx
|
|
||||||
import cupyx.scipy.fft
|
|
||||||
import cupyx.scipy.ndimage
|
|
||||||
import cupyx.scipy.signal
|
|
||||||
import cv2
|
import cv2
|
||||||
import scipy
|
import scipy
|
||||||
import scipy.signal
|
import scipy.signal
|
||||||
from cupyx.scipy.fft import dctn, idctn
|
# from cupyx.scipy.fft import dctn, idctn
|
||||||
from scipy.stats import norm as norms
|
from scipy.stats import norm as norms
|
||||||
|
|
||||||
from flandre.utils.RfFrame import RfFrame, RfFrameFile, RfFrameMemory
|
from flandre.utils.RfFrame import RfFrame, RfFrameFile, RfFrameMemory
|
||||||
@ -136,11 +128,12 @@ class RfMat:
|
|||||||
return None
|
return None
|
||||||
m = np.frombuffer(frame.__bytes__(), dtype=np.int16).reshape(seq_meta.shape).copy()
|
m = np.frombuffer(frame.__bytes__(), dtype=np.int16).reshape(seq_meta.shape).copy()
|
||||||
if device == 'gpu':
|
if device == 'gpu':
|
||||||
|
import cupy as cp
|
||||||
m = cp.asarray(m)
|
m = cp.asarray(m)
|
||||||
return RfMat(m, frame.meta, seq_meta)
|
return RfMat(m, frame.meta, seq_meta)
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
data: cp.ndarray,
|
data: np.ndarray,
|
||||||
frame_meta: RfFrameMeta = None,
|
frame_meta: RfFrameMeta = None,
|
||||||
seq_meta: RfSequenceMeta = None,
|
seq_meta: RfSequenceMeta = None,
|
||||||
):
|
):
|
||||||
@ -150,7 +143,7 @@ class RfMat:
|
|||||||
self.seq_meta = seq_meta
|
self.seq_meta = seq_meta
|
||||||
if isinstance(data, np.ndarray):
|
if isinstance(data, np.ndarray):
|
||||||
self.device = 'cpu'
|
self.device = 'cpu'
|
||||||
elif isinstance(data, cp.ndarray):
|
elif type(data).__module__ == 'cupy' and type(data).__name__ == 'ndarray':
|
||||||
self.device = 'gpu'
|
self.device = 'gpu'
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -183,6 +176,7 @@ class RfMat:
|
|||||||
def p(self):
|
def p(self):
|
||||||
if self.device == 'cpu':
|
if self.device == 'cpu':
|
||||||
return np
|
return np
|
||||||
|
import cupy as cp
|
||||||
return cp
|
return cp
|
||||||
|
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
@ -212,7 +206,7 @@ class RfMat:
|
|||||||
s = p.zeros_like(h) + 1
|
s = p.zeros_like(h) + 1
|
||||||
v = p.zeros_like(h) + 1
|
v = p.zeros_like(h) + 1
|
||||||
hsv = p.stack((h, s, v), axis=2)
|
hsv = p.stack((h, s, v), axis=2)
|
||||||
if p == cp:
|
if self.device == 'gpu':
|
||||||
rgb = hsv_to_rgb(hsv.get())
|
rgb = hsv_to_rgb(hsv.get())
|
||||||
else:
|
else:
|
||||||
rgb = hsv_to_rgb(hsv)
|
rgb = hsv_to_rgb(hsv)
|
||||||
@ -304,7 +298,8 @@ class RfMat:
|
|||||||
def dct(self, mmin, mmax):
|
def dct(self, mmin, mmax):
|
||||||
dct_ = scipy.fft.dct
|
dct_ = scipy.fft.dct
|
||||||
idct = scipy.fft.idct
|
idct = scipy.fft.idct
|
||||||
if self.p == cp:
|
if self.device == 'gpu':
|
||||||
|
import cupyx.scipy.fft
|
||||||
dct_ = cupyx.scipy.fft.dct
|
dct_ = cupyx.scipy.fft.dct
|
||||||
idct = cupyx.scipy.fft.idct
|
idct = cupyx.scipy.fft.idct
|
||||||
m_dct = dct_(self.m)
|
m_dct = dct_(self.m)
|
||||||
@ -327,7 +322,8 @@ class RfMat:
|
|||||||
arg = scipy.signal.argrelextrema
|
arg = scipy.signal.argrelextrema
|
||||||
m = self.m
|
m = self.m
|
||||||
p = self.p
|
p = self.p
|
||||||
if p == cp:
|
if self.device == 'gpu':
|
||||||
|
import cupyx.scipy.signal
|
||||||
arg = cupyx.scipy.signal.argrelextrema
|
arg = cupyx.scipy.signal.argrelextrema
|
||||||
rm = p.zeros_like(m)
|
rm = p.zeros_like(m)
|
||||||
indies1 = arg(m, p.greater, axis=axis)
|
indies1 = arg(m, p.greater, axis=axis)
|
||||||
@ -346,13 +342,14 @@ class RfMat:
|
|||||||
cv = scipy.ndimage.convolve1d
|
cv = scipy.ndimage.convolve1d
|
||||||
m = self.m
|
m = self.m
|
||||||
p = self.p
|
p = self.p
|
||||||
if p == cp:
|
if self.device == 'gpu':
|
||||||
|
import cupyx.scipy.ndimage
|
||||||
cv = cupyx.scipy.ndimage.convolve1d
|
cv = cupyx.scipy.ndimage.convolve1d
|
||||||
rv = norms(loc=0, scale=b)
|
rv = norms(loc=0, scale=b)
|
||||||
x2 = np.arange(-1, 1.1, 0.1)
|
x2 = np.arange(-1, 1.1, 0.1)
|
||||||
w = rv.pdf(x2)
|
w = rv.pdf(x2)
|
||||||
if p == cp:
|
if self.device == 'gpu':
|
||||||
w = cp.asarray(w)
|
w = p.asarray(w)
|
||||||
rm = cv(m, w, axis=axis)
|
rm = cv(m, w, axis=axis)
|
||||||
return self.copy(rm)
|
return self.copy(rm)
|
||||||
|
|
||||||
|
|||||||
5
test/type_test.py
Normal file
5
test/type_test.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import cupy as cp
|
||||||
|
if __name__ == '__main__':
|
||||||
|
p = cp.ndarray([1,2,3])
|
||||||
|
print(p.__class__.__name__)
|
||||||
|
print(type(p).__qualname__)
|
||||||
Loading…
Reference in New Issue
Block a user