Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abc
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
abc
Commits
235176d8
Commit
235176d8
authored
Dec 02, 2019
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates to JSON parser.
parent
787e3e1d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
6 deletions
+137
-6
src/base/io/io.c
+11
-5
src/base/io/ioJson.c
+126
-1
No files found.
src/base/io/io.c
View file @
235176d8
...
...
@@ -3309,14 +3309,18 @@ usage:
int
IoCommandWriteJson
(
Abc_Frame_t
*
pAbc
,
int
argc
,
char
**
argv
)
{
extern
void
Json_Write
(
char
*
pFileName
,
Abc_Nam_t
*
pStr
,
Vec_Wec_t
*
vObjs
);
extern
void
Json_Extract
(
char
*
pFileName
,
Abc_Nam_t
*
pStr
,
Vec_Wec_t
*
vObjs
);
int
c
,
fExtract
=
0
;
char
*
pFileName
;
int
c
;
Extra_UtilGetoptReset
();
while
(
(
c
=
Extra_UtilGetopt
(
argc
,
argv
,
"h"
)
)
!=
EOF
)
while
(
(
c
=
Extra_UtilGetopt
(
argc
,
argv
,
"
c
h"
)
)
!=
EOF
)
{
switch
(
c
)
{
case
'c'
:
fExtract
^=
1
;
break
;
case
'h'
:
goto
usage
;
default
:
...
...
@@ -3330,15 +3334,17 @@ int IoCommandWriteJson( Abc_Frame_t * pAbc, int argc, char **argv )
}
if
(
argc
!=
globalUtilOptind
+
1
)
goto
usage
;
// get the output file name
pFileName
=
argv
[
globalUtilOptind
];
// call the corresponding file writer
if
(
fExtract
)
Json_Extract
(
pFileName
,
Abc_FrameReadJsonStrs
(
Abc_FrameReadGlobalFrame
()),
Abc_FrameReadJsonObjs
(
Abc_FrameReadGlobalFrame
())
);
else
Json_Write
(
pFileName
,
Abc_FrameReadJsonStrs
(
Abc_FrameReadGlobalFrame
()),
Abc_FrameReadJsonObjs
(
Abc_FrameReadGlobalFrame
())
);
return
0
;
usage
:
fprintf
(
pAbc
->
Err
,
"usage: write_json [-h] <file>
\n
"
);
fprintf
(
pAbc
->
Err
,
"usage: write_json [-
c
h] <file>
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
write the network in JSON format
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
-c : output extracted version
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
-h : print the help message
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
file : the name of the file to write (extension .json)
\n
"
);
return
1
;
...
...
src/base/io/ioJson.c
View file @
235176d8
...
...
@@ -40,6 +40,131 @@ static inline Vec_Int_t * Json_EntryNode( Vec_Wec_t * vObjs, int Fan ) { asse
/**Function*************************************************************
Synopsis [Writes JSON into a file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
char
*
Nnc_LayerType2Str
(
char
*
pStr
)
{
if
(
!
strcmp
(
pStr
,
"InputLayer"
)
)
return
"input "
;
if
(
!
strcmp
(
pStr
,
"Conv2D"
)
)
return
"convo "
;
if
(
!
strcmp
(
pStr
,
"BatchNormalization"
)
)
return
"batch "
;
if
(
!
strcmp
(
pStr
,
"Activation"
)
)
return
"relu "
;
if
(
!
strcmp
(
pStr
,
"Add"
)
)
return
"eltwise"
;
if
(
!
strcmp
(
pStr
,
"MaxPooling2D"
)
)
return
"pool "
;
if
(
!
strcmp
(
pStr
,
"GlobalAveragePooling2D"
)
)
return
"pool "
;
if
(
!
strcmp
(
pStr
,
"Dense"
)
)
return
"fullcon"
;
if
(
!
strcmp
(
pStr
,
"ZeroPadding2D"
)
)
return
"pad"
;
// if ( !strcmp(pStr, "InputLayer") )
// return "softmax";
return
NULL
;
}
void
Json_Extract_rec
(
FILE
*
pFile
,
Abc_Nam_t
*
pStr
,
Vec_Wec_t
*
vObjs
,
Vec_Int_t
*
vArray
,
int
fWrite
,
int
*
pCount
)
{
int
i
,
Entry1
,
Entry2
;
if
(
Vec_IntEntry
(
vArray
,
0
)
)
// array
{
if
(
Vec_IntSize
(
vArray
)
==
1
)
return
;
if
(
Vec_IntSize
(
vArray
)
==
2
&&
Json_EntryIsName
(
Vec_IntEntry
(
vArray
,
1
))
)
{
if
(
fWrite
)
fprintf
(
pFile
,
"%s"
,
Json_EntryName
(
pStr
,
Vec_IntEntry
(
vArray
,
1
))
);
return
;
}
else
{
Vec_IntForEachEntryStart
(
vArray
,
Entry1
,
i
,
1
)
{
if
(
Json_EntryIsName
(
Entry1
)
)
{
int
Digit
=
Json_EntryName
(
pStr
,
Entry1
)[
0
];
if
(
fWrite
&&
Digit
!=
'0'
)
fprintf
(
pFile
,
"%s%s"
,
Json_EntryName
(
pStr
,
Entry1
),
Digit
>=
'0'
&&
Digit
<=
'9'
?
""
:
" "
);
}
else
Json_Extract_rec
(
pFile
,
pStr
,
vObjs
,
Json_EntryNode
(
vObjs
,
Entry1
),
fWrite
,
pCount
);
}
return
;
}
}
else
// list of pairs
{
int
fHaveConfig
=
0
;
assert
(
Vec_IntSize
(
vArray
)
%
2
!=
0
);
Vec_IntForEachEntryDoubleStart
(
vArray
,
Entry1
,
Entry2
,
i
,
1
)
{
char
*
pName1
=
Json_EntryIsName
(
Entry1
)
?
Json_EntryName
(
pStr
,
Entry1
)
:
NULL
;
char
*
pName2
=
Json_EntryIsName
(
Entry2
)
?
Json_EntryName
(
pStr
,
Entry2
)
:
NULL
;
char
*
pName3
=
pName2
?
Nnc_LayerType2Str
(
pName2
)
:
NULL
;
if
(
pName1
==
NULL
)
continue
;
if
(
!
strcmp
(
pName1
,
"class_name"
)
)
{
if
(
pName3
)
fprintf
(
pFile
,
"
\n
%3d : %-8s "
,
(
*
pCount
)
++
,
pName3
);
}
else
if
(
!
strcmp
(
pName1
,
"name"
)
)
{
if
(
fHaveConfig
)
fprintf
(
pFile
,
" N=%s "
,
pName2
?
pName2
:
"???"
);
}
else
if
(
!
strcmp
(
pName1
,
"kernel_size"
)
)
{
fprintf
(
pFile
,
" K="
);
Json_Extract_rec
(
pFile
,
pStr
,
vObjs
,
Json_EntryNode
(
vObjs
,
Entry2
),
1
,
pCount
);
}
else
if
(
!
strcmp
(
pName1
,
"strides"
)
)
{
fprintf
(
pFile
,
" S="
);
Json_Extract_rec
(
pFile
,
pStr
,
vObjs
,
Json_EntryNode
(
vObjs
,
Entry2
),
1
,
pCount
);
}
else
if
(
!
strcmp
(
pName1
,
"filters"
)
)
fprintf
(
pFile
,
" C=%s"
,
pName2
);
else
if
(
!
strcmp
(
pName1
,
"inbound_nodes"
)
)
Json_Extract_rec
(
pFile
,
pStr
,
vObjs
,
Json_EntryNode
(
vObjs
,
Entry2
),
1
,
pCount
);
else
if
(
!
strcmp
(
pName1
,
"layers"
)
)
Json_Extract_rec
(
pFile
,
pStr
,
vObjs
,
Json_EntryNode
(
vObjs
,
Entry2
),
1
,
pCount
);
else
if
(
!
strcmp
(
pName1
,
"config"
)
)
{
fHaveConfig
=
1
;
Json_Extract_rec
(
pFile
,
pStr
,
vObjs
,
Json_EntryNode
(
vObjs
,
Entry2
),
0
,
pCount
);
}
}
}
}
void
Json_Extract
(
char
*
pFileName
,
Abc_Nam_t
*
pStr
,
Vec_Wec_t
*
vObjs
)
{
int
Count
=
0
;
FILE
*
pFile
=
fopen
(
pFileName
,
"wb"
);
if
(
pFile
==
NULL
)
{
printf
(
"Cannot open file
\"
%s
\"
for writing.
\n
"
,
pFileName
);
return
;
}
fprintf
(
pFile
,
"# Data extracted from JSON file:
\n
"
);
Json_Extract_rec
(
pFile
,
pStr
,
vObjs
,
Vec_WecEntry
(
vObjs
,
0
),
0
,
&
Count
);
fprintf
(
pFile
,
"
\n
"
);
fclose
(
pFile
);
}
/**Function*************************************************************
Synopsis [Parsing.]
Description []
...
...
@@ -51,7 +176,7 @@ static inline Vec_Int_t * Json_EntryNode( Vec_Wec_t * vObjs, int Fan ) { asse
***********************************************************************/
static
inline
int
Json_CharIsSpace
(
char
c
)
{
return
(
c
==
' '
||
c
==
'\t'
||
c
==
'\r'
||
c
==
'\n'
);
return
(
c
==
' '
||
c
==
'\t'
||
c
==
'\r'
||
c
==
'\n'
||
c
==
':'
);
}
static
inline
char
*
Json_SkipSpaces
(
char
*
pCur
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment