Add OpenCV2 model

This commit is contained in:
Qing
2022-09-25 21:27:12 +08:00
parent bc98ea256a
commit 35cbbd653c
5 changed files with 88 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import React, { ReactNode } from 'react'
import { useRecoilState } from 'recoil'
import { AIModel, SDSampler, settingState } from '../../store/Atoms'
import { AIModel, CV2Flag, SDSampler, settingState } from '../../store/Atoms'
import Selector from '../shared/Selector'
import { Switch, SwitchThumb } from '../shared/Switch'
import Tooltip from '../shared/Tooltip'
@@ -133,6 +133,42 @@ function ModelSettingBlock() {
)
}
const renderOpenCV2Desc = () => {
return (
<>
<NumberInputSetting
title="Radius"
value={`${setting.cv2Radius}`}
desc="Radius of a circular neighborhood of each point inpainted that is considered by the algorithm."
onValue={value => {
const val = value.length === 0 ? 0 : parseInt(value, 10)
setSettingState(old => {
return { ...old, cv2Radius: val }
})
}}
/>
<SettingBlock
className="sub-setting-block"
title="Flag"
desc="Inpainting method"
input={
<Selector
width={140}
value={setting.cv2Flag as string}
options={Object.values(CV2Flag)}
onChange={val => {
setSettingState(old => {
return { ...old, cv2Flag: val as CV2Flag }
})
}}
/>
}
/>
</>
)
}
const renderOptionDesc = (): ReactNode => {
switch (setting.model) {
case AIModel.LAMA:
@@ -147,6 +183,8 @@ function ModelSettingBlock() {
return renderFCFModelDesc()
case AIModel.SD14:
return undefined
case AIModel.CV2:
return renderOpenCV2Desc()
default:
return <></>
}
@@ -190,6 +228,12 @@ function ModelSettingBlock() {
'https://ommer-lab.com/research/latent-diffusion-models/',
'https://github.com/CompVis/stable-diffusion'
)
case AIModel.CV2:
return renderModelDesc(
'OpenCV Image Inpainting',
'https://docs.opencv.org/4.6.0/df/d3d/tutorial_py_inpainting.html',
'https://docs.opencv.org/4.6.0/df/d3d/tutorial_py_inpainting.html'
)
default:
return <></>
}

View File

@@ -10,6 +10,7 @@ export enum AIModel {
MAT = 'mat',
FCF = 'fcf',
SD14 = 'sd1.4',
CV2 = 'cv2',
}
export const fileState = atom<File | undefined>({
@@ -132,6 +133,11 @@ export interface HDSettings {
type ModelsHDSettings = { [key in AIModel]: HDSettings }
export enum CV2Flag {
INPAINT_NS = 'INPAINT_NS',
INPAINT_TELEA = 'INPAINT_TELEA',
}
export interface Settings {
show: boolean
showCroper: boolean
@@ -158,6 +164,10 @@ export interface Settings {
sdSeed: number
sdSeedFixed: boolean // true: use sdSeed, false: random generate seed on backend
sdNumSamples: number
// For OpenCV2
cv2Radius: number
cv2Flag: CV2Flag
}
const defaultHDSettings: ModelsHDSettings = {
@@ -203,6 +213,13 @@ const defaultHDSettings: ModelsHDSettings = {
hdStrategyCropMargin: 128,
enabled: true,
},
[AIModel.CV2]: {
hdStrategy: HDStrategy.RESIZE,
hdStrategyResizeLimit: 1080,
hdStrategyCropTrigerSize: 512,
hdStrategyCropMargin: 128,
enabled: true,
},
}
export enum SDSampler {
@@ -240,6 +257,10 @@ export const settingStateDefault: Settings = {
sdSeed: 42,
sdSeedFixed: true,
sdNumSamples: 1,
// CV2
cv2Radius: 5,
cv2Flag: CV2Flag.INPAINT_NS,
}
const localStorageEffect =