@@ -252,7 +252,7 @@ class OnnxGraph {
252
252
var initializer = this . _initializerMap [ connection . id ] ;
253
253
if ( initializer ) {
254
254
connection . initializer = initializer ;
255
- connection . type = connection . type || initializer . type . toString ( ) ;
255
+ connection . type = connection . type || initializer . type ;
256
256
}
257
257
return connection ;
258
258
} ) ;
@@ -499,6 +499,7 @@ class OnnxTensor {
499
499
this . _tensor = tensor ;
500
500
this . _id = id ;
501
501
this . _kind = kind || null ;
502
+ this . _type = new OnnxTensorType ( this . _tensor . dataType , this . _tensor . dims . map ( ( dim ) => dim ) , null ) ;
502
503
}
503
504
504
505
get id ( ) {
@@ -514,7 +515,7 @@ class OnnxTensor {
514
515
}
515
516
516
517
get type ( ) {
517
- return new OnnxTensorType ( this . _tensor ) ;
518
+ return this . _type ;
518
519
}
519
520
520
521
get value ( ) {
@@ -744,37 +745,8 @@ class OnnxTensor {
744
745
745
746
static _formatType ( type , imageFormat ) {
746
747
if ( ! type ) {
747
- return { value : '?' } ;
748
+ return null ;
748
749
}
749
- var value = { } ;
750
- switch ( type . value ) {
751
- case 'tensorType' :
752
- var tensorType = type . tensorType ;
753
- var text = OnnxTensor . _formatElementType ( tensorType . elemType ) ;
754
- if ( tensorType . shape && tensorType . shape . dim ) {
755
- text += '[' + tensorType . shape . dim . map ( ( dimension ) => {
756
- if ( dimension . dimParam ) {
757
- return dimension . dimParam ;
758
- }
759
- return dimension . dimValue . toString ( ) ;
760
- } ) . join ( ',' ) + ']' ;
761
- }
762
- value = text ;
763
- break ;
764
- case 'mapType' :
765
- var keyType = OnnxTensor . _formatElementType ( type . mapType . keyType ) ;
766
- var valueType = OnnxTensor . _formatType ( type . mapType . valueType ) ;
767
- value = 'map<' + keyType + ',' + valueType . value + '>' ;
768
- break ;
769
- case 'sequenceType' :
770
- var elemType = OnnxTensor . _formatType ( type . sequenceType . elemType ) ;
771
- value = 'sequence<' + elemType . value + '>' ;
772
- break ;
773
- default :
774
- // debugger
775
- value = '?' ;
776
- break ;
777
- }
778
750
var denotation = '' ;
779
751
switch ( type . denotation ) {
780
752
case 'TENSOR' :
@@ -790,21 +762,30 @@ class OnnxTensor {
790
762
denotation = 'Text' ;
791
763
break ;
792
764
}
793
- return { value : value , denotation : denotation } ;
765
+ switch ( type . value ) {
766
+ case 'tensorType' :
767
+ var shape = [ ] ;
768
+ if ( type . tensorType . shape && type . tensorType . shape . dim ) {
769
+ shape = type . tensorType . shape . dim . map ( ( dim ) => {
770
+ return dim . dimParam ? dim . dimParam : dim . dimValue ;
771
+ } ) ;
772
+ }
773
+ return new OnnxTensorType ( type . tensorType . elemType , shape , denotation ) ;
774
+ case 'mapType' :
775
+ return new OnnxMapType ( type . mapType . keyType , OnnxTensor . _formatType ( type . mapType . valueType , imageFormat ) , denotation ) ;
776
+ case 'sequenceType' :
777
+ return new OnnxSequenceType ( OnnxTensor . _formatType ( type . sequenceType . elemType , imageFormat ) , denotation ) ;
778
+ }
779
+ return null ;
794
780
}
795
781
}
796
782
797
783
class OnnxTensorType {
798
784
799
- constructor ( tensor ) {
800
- this . _dataType = '?' ;
801
- if ( tensor . hasOwnProperty ( 'dataType' ) ) {
802
- this . _dataType = OnnxTensor . _formatElementType ( tensor . dataType ) ;
803
- }
804
- this . _shape = [ ] ;
805
- if ( tensor . hasOwnProperty ( 'dims' ) ) {
806
- this . _shape = tensor . dims . map ( ( dimension ) => dimension ) ;
807
- }
785
+ constructor ( dataType , shape , denotation ) {
786
+ this . _dataType = OnnxTensor . _formatElementType ( dataType ) ;
787
+ this . _shape = shape ;
788
+ this . _denotation = denotation || null ;
808
789
}
809
790
810
791
get dataType ( ) {
@@ -815,10 +796,58 @@ class OnnxTensorType {
815
796
return this . _shape ;
816
797
}
817
798
799
+ get denotation ( ) {
800
+ return this . _denotation ;
801
+ }
802
+
818
803
toString ( ) {
819
- return this . dataType + ( this . _shape ? ( '[' + this . _shape . map ( ( dimension ) => dimension . toString ( ) ) . join ( ',' ) + ']' ) : '' ) ;
804
+ return this . dataType + ( ( this . _shape && this . _shape . length ) ? ( '[' + this . _shape . join ( ',' ) + ']' ) : '' ) ;
820
805
}
806
+ }
807
+
808
+ class OnnxSequenceType {
809
+
810
+ constructor ( elementType , denotation ) {
811
+ this . _elementType = elementType ;
812
+ this . _denotation = denotation ;
813
+ }
814
+
815
+ get elementType ( ) {
816
+ return this . _elementType ;
817
+ }
818
+
819
+ get dennotation ( ) {
820
+ return this . _dennotation ;
821
+ }
822
+
823
+ toString ( ) {
824
+ return 'sequence<' + this . _elementType . toString ( ) + '>' ;
825
+ }
826
+ }
821
827
828
+ class OnnxMapType {
829
+
830
+ constructor ( keyType , valueType , denotation ) {
831
+ this . _keyType = OnnxTensor . _formatElementType ( keyType ) ;
832
+ this . _valueType = valueType ;
833
+ this . _denotation = denotation ;
834
+ }
835
+
836
+ get keyType ( ) {
837
+ return this . _keyType ;
838
+ }
839
+
840
+ get valueType ( ) {
841
+ return this . _valueType ;
842
+ }
843
+
844
+ get denotation ( ) {
845
+ return this . _denotation ;
846
+ }
847
+
848
+ toString ( ) {
849
+ return 'map<' + this . _keyType + ',' + this . _valueType . toString ( ) + '>' ;
850
+ }
822
851
}
823
852
824
853
class OnnxGraphOperatorMetadata {
0 commit comments