Changed InputOrder to ColorChannelOrder

The previous name was not clear enough.
This commit is contained in:
raystlin
2025-07-17 21:26:50 +00:00
parent adc4dc0f74
commit 1912f17aaf
4 changed files with 54 additions and 54 deletions

View File

@@ -54,11 +54,11 @@ func NewNasnet(assetsPath string, disabled bool) *Model {
TFVersion: "1.12.0",
Tags: []string{"photoprism"},
Input: &tensorflow.PhotoInput{
Name: "input_1",
Height: 224,
Width: 224,
ResizeOperation: tensorflow.CenterCrop,
InputOrder: tensorflow.RGB,
Name: "input_1",
Height: 224,
Width: 224,
ResizeOperation: tensorflow.CenterCrop,
ColorChannelOrder: tensorflow.RGB,
Intervals: []tensorflow.Interval{
{
Start: -1,

View File

@@ -61,7 +61,7 @@ func Image(img image.Image, input *PhotoInput) (tfTensor *tf.Tensor, err error)
}
var tfImage [1][][][3]float32
rIndex, gIndex, bIndex := input.InputOrder.Indices()
rIndex, gIndex, bIndex := input.ColorChannelOrder.Indices()
for j := 0; j < input.Resolution(); j++ {
tfImage[0] = append(tfImage[0], make([][3]float32, input.Resolution()))

View File

@@ -129,19 +129,19 @@ func (o *ResizeOperation) UnmarshalYAML(unmarshal func(interface{}) error) error
// How should we order the input vectors
// JSON and YAML functions are given to make it
// user friendly from the configuration files
type InputOrder int
type ColorChannelOrder int
const (
UndefinedOrder InputOrder = 0
RGB = 123
RBG = 132
GRB = 213
GBR = 231
BRG = 312
BGR = 321
UndefinedOrder ColorChannelOrder = 0
RGB = 123
RBG = 132
GRB = 213
GBR = 231
BRG = 312
BGR = 321
)
func (o InputOrder) Indices() (r, g, b int) {
func (o ColorChannelOrder) Indices() (r, g, b int) {
i := int(o)
if i == 0 {
@@ -165,7 +165,7 @@ func (o InputOrder) Indices() (r, g, b int) {
return
}
func (o InputOrder) String() string {
func (o ColorChannelOrder) String() string {
value := int(o)
if value == 0 {
@@ -196,7 +196,7 @@ func (o InputOrder) String() string {
return result
}
func NewInputOrder(val string) (InputOrder, error) {
func NewColorChannelOrder(val string) (ColorChannelOrder, error) {
if len(val) != 3 {
return UndefinedOrder, fmt.Errorf("Invalid length, expected 3")
}
@@ -222,20 +222,20 @@ func NewInputOrder(val string) (InputOrder, error) {
}
result = result*10 + index
}
return InputOrder(result), nil
return ColorChannelOrder(result), nil
}
func (o InputOrder) MarshalJSON() ([]byte, error) {
func (o ColorChannelOrder) MarshalJSON() ([]byte, error) {
return json.Marshal(o.String())
}
func (o *InputOrder) UnmarshalJSON(data []byte) error {
func (o *ColorChannelOrder) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
val, err := NewInputOrder(s)
val, err := NewColorChannelOrder(s)
if err != nil {
return err
}
@@ -244,17 +244,17 @@ func (o *InputOrder) UnmarshalJSON(data []byte) error {
return nil
}
func (o InputOrder) MarshalYAML() (any, error) {
func (o ColorChannelOrder) MarshalYAML() (any, error) {
return o.String(), nil
}
func (o *InputOrder) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (o *ColorChannelOrder) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
val, err := NewInputOrder(s)
val, err := NewColorChannelOrder(s)
if err != nil {
return err
}
@@ -264,13 +264,13 @@ func (o *InputOrder) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Input description for a photo input for a model
type PhotoInput struct {
Name string `yaml:"Name,omitempty" json:"name,omitempty"`
Intervals []Interval `yaml:"Intervals,omitempty" json:"intervals,omitempty"`
ResizeOperation ResizeOperation `yaml:"ResizeOperation,omitempty" json:"resizeOperation,omitemty"`
InputOrder InputOrder `yaml:"InputOrder,omitempty" json:"inputOrder,omitempty"`
OutputIndex int `yaml:"Index,omitempty" json:"index,omitempty"`
Height int64 `yaml:"Height,omitempty" json:"height,omitempty"`
Width int64 `yaml:"Width,omitempty" json:"width,omitempty"`
Name string `yaml:"Name,omitempty" json:"name,omitempty"`
Intervals []Interval `yaml:"Intervals,omitempty" json:"intervals,omitempty"`
ResizeOperation ResizeOperation `yaml:"ResizeOperation,omitempty" json:"resizeOperation,omitemty"`
ColorChannelOrder ColorChannelOrder `yaml:"ColorChannelOrder,omitempty" json:"inputOrder,omitempty"`
OutputIndex int `yaml:"Index,omitempty" json:"index,omitempty"`
Height int64 `yaml:"Height,omitempty" json:"height,omitempty"`
Width int64 `yaml:"Width,omitempty" json:"width,omitempty"`
}
// When dimensions are not defined, it means the model accepts any size of
@@ -331,8 +331,8 @@ func (p *PhotoInput) Merge(other *PhotoInput) {
p.ResizeOperation = other.ResizeOperation
}
if p.InputOrder == UndefinedOrder {
p.InputOrder = other.InputOrder
if p.ColorChannelOrder == UndefinedOrder {
p.ColorChannelOrder = other.ColorChannelOrder
}
}

View File

@@ -88,7 +88,7 @@ func TestResizeOperationYAML(t *testing.T) {
}
// Resize Operation Tests
var allInputOrders = []InputOrder{
var allColorChannelOrders = []ColorChannelOrder{
RGB,
RBG,
GRB,
@@ -97,23 +97,23 @@ var allInputOrders = []InputOrder{
BGR,
}
func TestInputOrders(t *testing.T) {
for i := range allInputOrders {
text := allInputOrders[i].String()
func TestColorChannelOrders(t *testing.T) {
for i := range allColorChannelOrders {
text := allColorChannelOrders[i].String()
order, err := NewInputOrder(text)
order, err := NewColorChannelOrder(text)
if err != nil {
t.Fatalf("Invalid order %s: %v", text, err)
}
assert.Equal(t, order, allInputOrders[i])
assert.Equal(t, order, allColorChannelOrders[i])
}
}
const exampleOrderJSON = `"RGB"`
func TestInputOrderJSON(t *testing.T) {
var order InputOrder
func TestColorChannelOrderJSON(t *testing.T) {
var order ColorChannelOrder
err := json.Unmarshal(
[]byte(exampleOrderJSON), &order)
@@ -122,11 +122,11 @@ func TestInputOrderJSON(t *testing.T) {
t.Fatal("Could not unmarshal the example operation")
}
for i := range allInputOrders {
serialized, err := json.Marshal(allInputOrders[i])
for i := range allColorChannelOrders {
serialized, err := json.Marshal(allColorChannelOrders[i])
if err != nil {
t.Fatalf("Could not marshal %v: %v",
allInputOrders[i], err)
allColorChannelOrders[i], err)
}
err = json.Unmarshal(serialized, &order)
@@ -135,14 +135,14 @@ func TestInputOrderJSON(t *testing.T) {
string(serialized), err)
}
assert.Equal(t, order, allInputOrders[i])
assert.Equal(t, order, allColorChannelOrders[i])
}
}
const exampleOrderYAML = "RGB"
func TestInputOrderYAML(t *testing.T) {
var order InputOrder
func TestColorChannelOrderYAML(t *testing.T) {
var order ColorChannelOrder
err := yaml.Unmarshal(
[]byte(exampleOrderYAML), &order)
@@ -151,11 +151,11 @@ func TestInputOrderYAML(t *testing.T) {
t.Fatal("Could not unmarshal the example operation")
}
for i := range allInputOrders {
serialized, err := yaml.Marshal(allInputOrders[i])
for i := range allColorChannelOrders {
serialized, err := yaml.Marshal(allColorChannelOrders[i])
if err != nil {
t.Fatalf("Could not marshal %v: %v",
allInputOrders[i], err)
allColorChannelOrders[i], err)
}
err = yaml.Unmarshal(serialized, &order)
@@ -164,7 +164,7 @@ func TestInputOrderYAML(t *testing.T) {
string(serialized), err)
}
assert.Equal(t, order, allInputOrders[i])
assert.Equal(t, order, allColorChannelOrders[i])
}
}
@@ -188,8 +188,8 @@ func TestOrderIndices(t *testing.T) {
}
}
for i := range allInputOrders {
r, g, b = allInputOrders[i].Indices()
assert.Equal(t, powerFx(r)+2*powerFx(g)+3*powerFx(b), int(allInputOrders[i]))
for i := range allColorChannelOrders {
r, g, b = allColorChannelOrders[i].Indices()
assert.Equal(t, powerFx(r)+2*powerFx(g)+3*powerFx(b), int(allColorChannelOrders[i]))
}
}