Why doesn't ghostscript like the ICC profile of my PDF? - imagemagick

I can run the following GhostScript to successfully combine multiple PDFs into one file:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=test.pdf file1.pdf file2.pdf file3.pdf
I also need to add a custom overlay to the PDF so I am doing the following:
convert -density 300 -quality 100 file1.pdf -font /usr/share/fonts/urw-base35/NimbusSansNarrow-Regular.otf -pointsize 15 -fill '#000000' -draw 'rectangle 21,1114,675,1220' -fill white -annotate +440+1160 '1 / 3' -annotate +34+1213 'file1.pdf' file1_a.pdf
...for each PDF, then I run the first gs command again to combine those annotated PDFs, but when I do so I'm getting the following error:
**** Error: ICCbased space /N value does not match the ICC profile.
Using the number of channels from the profile.
Output may be incorrect.
I did find something that looks related, suggesting it is the PDF that is wrong: https://bugs.ghostscript.com/show_bug.cgi?id=697223
Well, fundamentally your PDF file is broken. It uses ICCBased colour
spaces, and the number of declared components in the colour space
doesn't match the actual content of the ICC profile.
If this does relate to my situation, I'm not sure if this is the PDF after I annotate or if there's something underlying already in the original files (file1.pdf, etc, in the above examples). As mentioned earlier, when I just process the original files, they work, but it doesn't after annotating them.
The weird thing is that this started happening at about 3pm today, after a successful run earlier in the day about 2 hours previous and no code or environment changes have taken place and it has been running for months this way without issue. The original PDFs come from an external source.
Where can I look next to figure out the cause of this issue?
Update
Here is a dump of one of the singles files before and after annotating:
Before
Image: 1160914.pdf
Format: PDF (Portable Document Format)
Mime type: application/pdf
Class: DirectClass
Geometry: 283x425+0+0
Resolution: 72x72
Print size: 3.93056x5.90278
Units: Undefined
Colorspace: sRGB
Type: Bilevel
Base type: Undefined
Endianess: Undefined
Depth: 16/8-bit
Channel depth:
red: 1-bit
green: 1-bit
blue: 1-bit
alpha: 8-bit
Channel statistics:
Pixels: 120275
Red:
min: 0 (0)
max: 65535 (1)
mean: 1233.6 (0.0188235)
standard deviation: 8906.34 (0.135902)
kurtosis: 48.1433
skewness: 7.08117
entropy: 0.134783
Green:
min: 0 (0)
max: 65535 (1)
mean: 1233.6 (0.0188235)
standard deviation: 8906.34 (0.135902)
kurtosis: 48.1433
skewness: 7.08117
entropy: 0.134783
Blue:
min: 0 (0)
max: 65535 (1)
mean: 1233.6 (0.0188235)
standard deviation: 8906.34 (0.135902)
kurtosis: 48.1433
skewness: 7.08117
entropy: 0.134783
Alpha:
min: 0 (0)
max: 65535 (1)
mean: 9929.07 (0.151508)
standard deviation: 20805.3 (0.317469)
kurtosis: 1.91296
skewness: 1.8744
entropy: 0.224671
Image statistics:
Overall:
min: 0 (0)
max: 65535 (1)
mean: 3407.47 (0.0519946)
standard deviation: 11881.1 (0.181294)
kurtosis: 14.4936
skewness: 3.98008
entropy: 0.157255
Alpha: srgba(255,255,255,0) #FFFFFFFFFFFF0000
Colors: 93
Histogram:
91860: ( 0, 0, 0, 0) #0000000000000000 none
9477: ( 0, 0, 0,65535) #000000000000FFFF black
4066: ( 0, 0, 0,34952) #0000000000008888 srgba(0,0,0,0.533333)
3476: ( 0, 0, 0,17476) #0000000000004444 srgba(0,0,0,0.266667)
3180: ( 0, 0, 0,48059) #000000000000BBBB srgba(0,0,0,0.733333)
651: ( 0, 0, 0,57311) #000000000000DFDF srgba(0,0,0,0.87451)
434: ( 0, 0, 0,26214) #0000000000006666 srgba(0,0,0,0.4)
420: ( 0, 0, 0,13107) #0000000000003333 srgba(0,0,0,0.2)
392: ( 0, 0, 0, 8738) #0000000000002222 srgba(0,0,0,0.133333)
355: ( 0, 0, 0, 4369) #0000000000001111 srgba(0,0,0,0.0666667)
347: ( 0, 0, 0,30326) #0000000000007676 srgba(0,0,0,0.462745)
231: ( 0, 0, 0,47288) #000000000000B8B8 srgba(0,0,0,0.721569)
226: ( 0, 0, 0,51143) #000000000000C7C7 srgba(0,0,0,0.780392)
192: ( 0, 0, 0,39064) #0000000000009898 srgba(0,0,0,0.596078)
186: ( 0, 0, 0,36751) #0000000000008F8F srgba(0,0,0,0.560784)
184: ( 0, 0, 0,52428) #000000000000CCCC srgba(0,0,0,0.8)
182: ( 0, 0, 0,43690) #000000000000AAAA srgba(0,0,0,0.666667)
181: ( 0, 0, 0,39321) #0000000000009999 srgba(0,0,0,0.6)
178: ( 0, 0, 0,51657) #000000000000C9C9 srgba(0,0,0,0.788235)
166: ( 0, 0, 0,56797) #000000000000DDDD srgba(0,0,0,0.866667)
163: ( 0, 0, 0,52685) #000000000000CDCD srgba(0,0,0,0.803922)
152: ( 0, 0, 0,60909) #000000000000EDED srgba(0,0,0,0.929412)
148: ( 0, 0, 0,61166) #000000000000EEEE srgba(0,0,0,0.933333)
145: ( 0, 0, 0,21845) #0000000000005555 srgba(0,0,0,0.333333)
136: ( 0, 0, 0,41120) #000000000000A0A0 srgba(0,0,0,0.627451)
132: ( 0, 0, 0,30583) #0000000000007777 srgba(0,0,0,0.466667)
120: ( 0, 0, 0,50372) #000000000000C4C4 srgba(0,0,0,0.768627)
117: ( 0, 0, 0,43176) #000000000000A8A8 srgba(0,0,0,0.658824)
112: ( 0, 0, 0,20046) #0000000000004E4E srgba(0,0,0,0.305882)
101: ( 0, 0, 0,20560) #0000000000005050 srgba(0,0,0,0.313725)
68: ( 0, 0, 0,54998) #000000000000D6D6 srgba(0,0,0,0.839216)
55: ( 0, 0, 0,41891) #000000000000A3A3 srgba(0,0,0,0.639216)
21: ( 0, 0, 0,46003) #000000000000B3B3 srgba(0,0,0,0.701961)
15: ( 0, 0, 0,23644) #0000000000005C5C srgba(0,0,0,0.360784)
13: ( 0, 0, 0,34695) #0000000000008787 srgba(0,0,0,0.529412)
13: ( 0, 0, 0,34181) #0000000000008585 srgba(0,0,0,0.521569)
12: ( 0, 0, 0,39835) #0000000000009B9B srgba(0,0,0,0.607843)
10: ( 0, 0, 0,61937) #000000000000F1F1 srgba(0,0,0,0.945098)
10: ( 0, 0, 0,33924) #0000000000008484 srgba(0,0,0,0.517647)
9: ( 0, 0, 0,32639) #0000000000007F7F srgba(0,0,0,0.498039)
6: ( 0, 0, 0,29298) #0000000000007272 srgba(0,0,0,0.447059)
4: ( 0, 0, 0,25957) #0000000000006565 srgba(0,0,0,0.396078)
3: ( 0, 0, 0,58853) #000000000000E5E5 srgba(0,0,0,0.898039)
3: ( 0, 0, 0, 8481) #0000000000002121 srgba(0,0,0,0.129412)
3: ( 0, 0, 0, 2056) #0000000000000808 srgba(0,0,0,0.0313725)
2: ( 0, 0, 0,65021) #000000000000FDFD srgba(0,0,0,0.992157)
2: ( 0, 0, 0,64250) #000000000000FAFA srgba(0,0,0,0.980392)
2: ( 0, 0, 0,63736) #000000000000F8F8 srgba(0,0,0,0.972549)
2: ( 0, 0, 0,49087) #000000000000BFBF srgba(0,0,0,0.74902)
2: ( 0, 0, 0,33410) #0000000000008282 srgba(0,0,0,0.509804)
2: ( 0, 0, 0,28784) #0000000000007070 srgba(0,0,0,0.439216)
2: ( 0, 0, 0,16705) #0000000000004141 srgba(0,0,0,0.254902)
2: ( 0, 0, 0,16191) #0000000000003F3F srgba(0,0,0,0.247059)
2: ( 0, 0, 0, 1028) #0000000000000404 srgba(0,0,0,0.0156863)
1: ( 0, 0, 0,64507) #000000000000FBFB srgba(0,0,0,0.984314)
1: ( 0, 0, 0,63993) #000000000000F9F9 srgba(0,0,0,0.976471)
1: ( 0, 0, 0,63479) #000000000000F7F7 srgba(0,0,0,0.968627)
1: ( 0, 0, 0,62451) #000000000000F3F3 srgba(0,0,0,0.952941)
1: ( 0, 0, 0,62194) #000000000000F2F2 srgba(0,0,0,0.94902)
1: ( 0, 0, 0,61423) #000000000000EFEF srgba(0,0,0,0.937255)
1: ( 0, 0, 0,60652) #000000000000ECEC srgba(0,0,0,0.92549)
1: ( 0, 0, 0,59367) #000000000000E7E7 srgba(0,0,0,0.905882)
1: ( 0, 0, 0,57825) #000000000000E1E1 srgba(0,0,0,0.882353)
1: ( 0, 0, 0,55255) #000000000000D7D7 srgba(0,0,0,0.843137)
1: ( 0, 0, 0,54484) #000000000000D4D4 srgba(0,0,0,0.831373)
1: ( 0, 0, 0,53970) #000000000000D2D2 srgba(0,0,0,0.823529)
1: ( 0, 0, 0,49344) #000000000000C0C0 srgba(0,0,0,0.752941)
1: ( 0, 0, 0,46517) #000000000000B5B5 srgba(0,0,0,0.709804)
1: ( 0, 0, 0,45232) #000000000000B0B0 srgba(0,0,0,0.690196)
1: ( 0, 0, 0,42405) #000000000000A5A5 srgba(0,0,0,0.647059)
1: ( 0, 0, 0,40606) #0000000000009E9E srgba(0,0,0,0.619608)
1: ( 0, 0, 0,36494) #0000000000008E8E srgba(0,0,0,0.556863)
1: ( 0, 0, 0,35209) #0000000000008989 srgba(0,0,0,0.537255)
1: ( 0, 0, 0,31868) #0000000000007C7C srgba(0,0,0,0.486275)
1: ( 0, 0, 0,31354) #0000000000007A7A srgba(0,0,0,0.478431)
1: ( 0, 0, 0,29555) #0000000000007373 srgba(0,0,0,0.45098)
1: ( 0, 0, 0,29041) #0000000000007171 srgba(0,0,0,0.443137)
1: ( 0, 0, 0,27756) #0000000000006C6C srgba(0,0,0,0.423529)
1: ( 0, 0, 0,26471) #0000000000006767 srgba(0,0,0,0.403922)
1: ( 0, 0, 0,23901) #0000000000005D5D srgba(0,0,0,0.364706)
1: ( 0, 0, 0,21331) #0000000000005353 srgba(0,0,0,0.32549)
1: ( 0, 0, 0,19018) #0000000000004A4A srgba(0,0,0,0.290196)
1: ( 0, 0, 0,15677) #0000000000003D3D srgba(0,0,0,0.239216)
1: ( 0, 0, 0,15163) #0000000000003B3B srgba(0,0,0,0.231373)
1: ( 0, 0, 0,14649) #0000000000003939 srgba(0,0,0,0.223529)
1: ( 0, 0, 0,12593) #0000000000003131 srgba(0,0,0,0.192157)
1: ( 0, 0, 0,11308) #0000000000002C2C srgba(0,0,0,0.172549)
1: ( 0, 0, 0, 8224) #0000000000002020 srgba(0,0,0,0.12549)
1: ( 0, 0, 0, 2570) #0000000000000A0A srgba(0,0,0,0.0392157)
1: ( 0, 0, 0, 2313) #0000000000000909 srgba(0,0,0,0.0352941)
1: ( 0, 0, 0, 771) #0000000000000303 srgba(0,0,0,0.0117647)
1: ( 0, 0, 0, 514) #0000000000000202 srgba(0,0,0,0.00784314)
2264: (65535,65535,65535, 0) #FFFFFFFFFFFF0000 srgba(255,255,255,0)
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 283x425+0+0
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Properties:
date:create: 2020-07-09T10:15:48+00:00
date:modify: 2020-07-09T10:15:48+00:00
icc:copyright: Copyright Artifex Software 2011
icc:description: Artifex Software sRGB ICC Profile
pdf:HiResBoundingBox: 283.464x425.196+0+0
pdf:Version: PDF-1.4
signature: 00e501c6231c0d8d04c23e84b4e6268a0b36c8776e662d11a26fcbf2e7734c37
Profiles:
Profile-icc: 2576 bytes
Artifacts:
filename: 1160914.pdf
verbose: true
Tainted: False
Filesize: 19048B
Number pixels: 120275
Pixels per second: 54.4276MB
User time: 0.000u
Elapsed time: 0:01.002
Version: ImageMagick 6.9.10-68 Q16 x86_64 2020-04-01 https://imagemagick.org
After
Image: 1160914_a.pdf
Format: PDF (Portable Document Format)
Mime type: application/pdf
Class: DirectClass
Geometry: 283x425+0+0
Resolution: 72x72
Print size: 3.93056x5.90278
Units: Undefined
Colorspace: sRGB
Type: PaletteAlpha
Base type: Undefined
Endianess: Undefined
Depth: 16/8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit
Channel statistics:
Pixels: 120275
Red:
min: 0 (0)
max: 65535 (1)
mean: 44179 (0.674128)
standard deviation: 30711.8 (0.468632)
kurtosis: -1.44771
skewness: -0.742992
entropy: 0.168105
Green:
min: 0 (0)
max: 65535 (1)
mean: 44180.2 (0.674147)
standard deviation: 30710.7 (0.468615)
kurtosis: -1.44757
skewness: -0.743073
entropy: 0.165488
Blue:
min: 0 (0)
max: 65535 (1)
mean: 44185.1 (0.674221)
standard deviation: 30710.6 (0.468614)
kurtosis: -1.44705
skewness: -0.743479
entropy: 0.177214
Alpha:
min: 0 (0)
max: 65535 (1)
mean: 3093.15 (0.0471984)
standard deviation: 13504.7 (0.206068)
kurtosis: 16.414
skewness: 4.26005
entropy: 0.0635703
Image statistics:
Overall:
min: 0 (0)
max: 65535 (1)
mean: 33909.4 (0.517424)
standard deviation: 26409.4 (0.402982)
kurtosis: -1.9929
skewness: -0.0698118
entropy: 0.143594
Alpha: srgba(255,255,255,0) #FFFFFFFFFFFF0000
Colors: 179
Histogram:
32788: ( 0, 0, 0, 0) #0000000000000000 none
4794: ( 0, 0, 0,65535) #000000000000FFFF black
432: ( 0, 0, 0,17476) #0000000000004444 srgba(0,0,0,0.266667)
379: ( 0, 0, 0,34952) #0000000000008888 srgba(0,0,0,0.533333)
322: ( 0, 0, 0,48059) #000000000000BBBB srgba(0,0,0,0.733333)
174: ( 0, 0, 0,57311) #000000000000DFDF srgba(0,0,0,0.87451)
16: ( 0, 0, 0, 8738) #0000000000002222 srgba(0,0,0,0.133333)
15: ( 0, 0, 0,20560) #0000000000005050 srgba(0,0,0,0.313725)
14: ( 0, 0, 0,41120) #000000000000A0A0 srgba(0,0,0,0.627451)
12: ( 0, 0, 0,47288) #000000000000B8B8 srgba(0,0,0,0.721569)
12: ( 0, 0, 0,20046) #0000000000004E4E srgba(0,0,0,0.305882)
12: ( 0, 0, 0,11565) #0000000000002D2D srgba(0,0,0,0.176471)
11: ( 0, 0, 0,50372) #000000000000C4C4 srgba(0,0,0,0.768627)
10: ( 0, 0, 0,26214) #0000000000006666 srgba(0,0,0,0.4)
9: ( 0, 0, 0,13107) #0000000000003333 srgba(0,0,0,0.2)
8: ( 0, 0, 0, 4369) #0000000000001111 srgba(0,0,0,0.0666667)
7: ( 0, 0, 0,54998) #000000000000D6D6 srgba(0,0,0,0.839216)
7: ( 0, 0, 0,52685) #000000000000CDCD srgba(0,0,0,0.803922)
7: ( 0, 0, 0,43176) #000000000000A8A8 srgba(0,0,0,0.658824)
7: ( 0, 0, 0,30326) #0000000000007676 srgba(0,0,0,0.462745)
6: ( 0, 0, 0,51657) #000000000000C9C9 srgba(0,0,0,0.788235)
6: ( 0, 0, 0,18761) #0000000000004949 srgba(0,0,0,0.286275)
5: ( 0, 0, 0,65278) #000000000000FEFE srgba(0,0,0,0.996078)
5: ( 0, 0, 0,39064) #0000000000009898 srgba(0,0,0,0.596078)
4: ( 0, 0, 0,36751) #0000000000008F8F srgba(0,0,0,0.560784)
3: ( 0, 0, 0,65021) #000000000000FDFD srgba(0,0,0,0.992157)
3: ( 0, 0, 0,64507) #000000000000FBFB srgba(0,0,0,0.984314)
3: ( 0, 0, 0,61166) #000000000000EEEE srgba(0,0,0,0.933333)
3: ( 0, 0, 0,56797) #000000000000DDDD srgba(0,0,0,0.866667)
3: ( 0, 0, 0,52428) #000000000000CCCC srgba(0,0,0,0.8)
3: ( 0, 0, 0,51143) #000000000000C7C7 srgba(0,0,0,0.780392)
3: ( 0, 0, 0,12336) #0000000000003030 srgba(0,0,0,0.188235)
2: ( 0, 0, 0,62965) #000000000000F5F5 srgba(0,0,0,0.960784)
2: ( 0, 0, 0,43690) #000000000000AAAA srgba(0,0,0,0.666667)
2: ( 0, 0, 0,40606) #0000000000009E9E srgba(0,0,0,0.619608)
2: ( 0, 0, 0,39321) #0000000000009999 srgba(0,0,0,0.6)
2: ( 0, 0, 0,30840) #0000000000007878 srgba(0,0,0,0.470588)
2: ( 0, 0, 0, 1799) #0000000000000707 srgba(0,0,0,0.027451)
2: ( 0, 0, 0, 514) #0000000000000202 srgba(0,0,0,0.00784314)
1: ( 0, 0, 0,64250) #000000000000FAFA srgba(0,0,0,0.980392)
1: ( 0, 0, 0,61937) #000000000000F1F1 srgba(0,0,0,0.945098)
1: ( 0, 0, 0,60138) #000000000000EAEA srgba(0,0,0,0.917647)
1: ( 0, 0, 0,59624) #000000000000E8E8 srgba(0,0,0,0.909804)
1: ( 0, 0, 0,59110) #000000000000E6E6 srgba(0,0,0,0.901961)
1: ( 0, 0, 0,55512) #000000000000D8D8 srgba(0,0,0,0.847059)
1: ( 0, 0, 0,49601) #000000000000C1C1 srgba(0,0,0,0.756863)
1: ( 0, 0, 0,48573) #000000000000BDBD srgba(0,0,0,0.741176)
1: ( 0, 0, 0,47802) #000000000000BABA srgba(0,0,0,0.729412)
1: ( 0, 0, 0,44204) #000000000000ACAC srgba(0,0,0,0.67451)
1: ( 0, 0, 0,42662) #000000000000A6A6 srgba(0,0,0,0.65098)
1: ( 0, 0, 0,41891) #000000000000A3A3 srgba(0,0,0,0.639216)
1: ( 0, 0, 0,39578) #0000000000009A9A srgba(0,0,0,0.603922)
1: ( 0, 0, 0,30583) #0000000000007777 srgba(0,0,0,0.466667)
1: ( 0, 0, 0,21845) #0000000000005555 srgba(0,0,0,0.333333)
1: ( 0, 0, 0,17990) #0000000000004646 srgba(0,0,0,0.27451)
1: ( 0, 0, 0,18247) #0000000000004747 srgba(0,0,0,0.278431)
1: ( 0, 0, 0,16962) #0000000000004242 srgba(0,0,0,0.258824)
1: ( 0, 0, 0,14392) #0000000000003838 srgba(0,0,0,0.219608)
1: ( 0, 0, 0,10794) #0000000000002A2A srgba(0,0,0,0.164706)
1: ( 0, 0, 0,10537) #0000000000002929 srgba(0,0,0,0.160784)
1: ( 0, 0, 0, 6682) #0000000000001A1A srgba(0,0,0,0.101961)
1: ( 0, 0, 0, 3855) #0000000000000F0F srgba(0,0,0,0.0588235)
1: ( 0, 0, 0, 3341) #0000000000000D0D srgba(0,0,0,0.0509804)
1: ( 0, 0, 0, 1028) #0000000000000404 srgba(0,0,0,0.0156863)
1: ( 0, 0, 5654,65535) #000000001616FFFF srgba(0,0,22,1)
1: ( 0, 0,13364,65535) #000000003434FFFF srgba(0,0,52,1)
1: ( 0, 0,16191, 0) #000000003F3F0000 srgba(0,0,63,0)
1: ( 0, 0,16448,65535) #000000004040FFFF srgba(0,0,64,1)
1: ( 0, 0,20046, 0) #000000004E4E0000 srgba(0,0,78,0)
1: ( 0, 0,25186, 0) #0000000062620000 srgba(0,0,98,0)
1: ( 0, 0,33153, 0) #0000000081810000 srgba(0,0,129,0)
1: ( 0, 0,37779, 0) #0000000093930000 srgba(0,0,147,0)
1: ( 0, 0,40349, 0) #000000009D9D0000 srgba(0,0,157,0)
1: ( 0, 0,46774, 0) #00000000B6B60000 srgba(0,0,182,0)
1: ( 0, 0,49601, 0) #00000000C1C10000 srgba(0,0,193,0)
1: ( 0, 0,52171, 0) #00000000CBCB0000 srgba(0,0,203,0)
1: ( 0, 257,59881, 0) #00000101E9E90000 srgba(0,1,233,0)
1: ( 0, 1285,55512, 0) #00000505D8D80000 srgba(0,5,216,0)
1: ( 0, 3084,64250,65535) #00000C0CFAFAFFFF srgba(0,12,250,1)
1: ( 0, 7967,63736,65535) #00001F1FF8F8FFFF srgba(0,31,248,1)
1: ( 0,10280,64764,17476) #00002828FCFC4444 srgba(0,40,252,0.266667)
1: ( 0,11822,65021, 0) #00002E2EFDFD0000 srgba(0,46,253,0)
8: ( 0,12079,65535, 0) #00002F2FFFFF0000 srgba(0,47,255,0)
1: ( 0,14392,65535, 0) #00003838FFFF0000 srgba(0,56,255,0)
4: ( 0,16191,65535, 0) #00003F3FFFFF0000 srgba(0,63,255,0)
1: ( 0,17990,65535, 0) #00004646FFFF0000 srgba(0,70,255,0)
1: ( 0,18761,65535,65535) #00004949FFFFFFFF srgba(0,73,255,1)
2: ( 0,20817,65535, 0) #00005151FFFF0000 srgba(0,81,255,0)
1: ( 0,33410,65535, 0) #00008282FFFF0000 srgba(0,130,255,0)
1: ( 0,41377,65535,65535) #0000A1A1FFFFFFFF srgba(0,161,255,1)
1: ( 0,42919,65535, 0) #0000A7A7FFFF0000 srgba(0,167,255,0)
1: ( 0,52171,65535, 0) #0000CBCBFFFF0000 srgba(0,203,255,0)
2: ( 0,53199,65535, 0) #0000CFCFFFFF0000 srgba(0,207,255,0)
1: ( 0,57054,65535, 0) #0000DEDEFFFF0000 srgba(0,222,255,0)
1: ( 0,58853,65535, 0) #0000E5E5FFFF0000 srgba(0,229,255,0)
1: ( 771,55255,65535, 0) #0303D7D7FFFF0000 srgba(3,215,255,0)
1: ( 771,62194,65535,65535) #0303F2F2FFFFFFFF srgba(3,242,255,1)
1: ( 1542, 0, 0, 0) #0606000000000000 srgba(6,0,0,0)
1: ( 2313, 0, 0,65535) #090900000000FFFF srgba(9,0,0,1)
1: ( 3084, 0, 0,65535) #0C0C00000000FFFF srgba(12,0,0,1)
1: ( 3084,15934,39578,65535) #0C0C3E3E9A9AFFFF srgba(12,62,154,1)
1: ( 4626,65021,65535, 0) #1212FDFDFFFF0000 srgba(18,253,255,0)
1: ( 4883, 0, 0,65535) #131300000000FFFF srgba(19,0,0,1)
1: ( 6425, 0, 0,17476) #1919000000004444 srgba(25,0,0,0.266667)
1: ( 8995, 0, 0, 0) #2323000000000000 srgba(35,0,0,0)
1: ( 9252, 0, 0, 0) #2424000000000000 srgba(36,0,0,0)
1: ( 9252,65535,65535, 0) #2424FFFFFFFF0000 srgba(36,255,255,0)
1: (10537,64764,65535, 0) #2929FCFCFFFF0000 srgba(41,252,255,0)
4: (12079,65535,65535, 0) #2F2FFFFFFFFF0000 srgba(47,255,255,0)
1: (13364,65278,65535,65535) #3434FEFEFFFFFFFF srgba(52,254,255,1)
1: (14906,60138,65535,65535) #3A3AEAEAFFFFFFFF srgba(58,234,255,1)
1: (15677, 0, 0,65535) #3D3D00000000FFFF srgba(61,0,0,1)
1: (16962,65535,65535,65535) #4242FFFFFFFFFFFF srgba(66,255,255,1)
1: (18504, 0, 0, 0) #4848000000000000 srgba(72,0,0,0)
1: (19532, 0, 0, 0) #4C4C000000000000 srgba(76,0,0,0)
1: (24158, 0, 0,65535) #5E5E00000000FFFF srgba(94,0,0,1)
1: (24415,65535,65535, 0) #5F5FFFFFFFFF0000 srgba(95,255,255,0)
1: (25186, 0, 0,65535) #626200000000FFFF srgba(98,0,0,1)
1: (26214,65535,65535,48059) #6666FFFFFFFFBBBB srgba(102,255,255,0.733333)
1: (29298,58339,65535, 0) #7272E3E3FFFF0000 srgba(114,227,255,0)
1: (31097, 0, 0, 0) #7979000000000000 srgba(121,0,0,0)
1: (31097,65535,65535, 0) #7979FFFFFFFF0000 srgba(121,255,255,0)
1: (32896, 0, 0,65535) #808000000000FFFF maroon
1: (34438, 0, 0,65535) #868600000000FFFF srgba(134,0,0,1)
1: (34952,65535,65535,65535) #8888FFFFFFFFFFFF srgba(136,255,255,1)
1: (37265,65535,65535,65535) #9191FFFFFFFFFFFF srgba(145,255,255,1)
1: (39321, 0, 0,65535) #999900000000FFFF srgba(153,0,0,1)
1: (42148, 0, 0,65535) #A4A400000000FFFF srgba(164,0,0,1)
1: (42919, 257, 0, 0) #A7A7010100000000 srgba(167,1,0,0)
1: (44204, 0, 0,65535) #ACAC00000000FFFF srgba(172,0,0,1)
1: (44975,65535,65535, 0) #AFAFFFFFFFFF0000 srgba(175,255,255,0)
1: (48059, 0, 0, 0) #BBBB000000000000 srgba(187,0,0,0)
1: (48059,65535,65535,65535) #BBBBFFFFFFFFFFFF srgba(187,255,255,1)
1: (49344, 0, 0,17476) #C0C0000000004444 srgba(192,0,0,0.266667)
1: (50629,65535,65535, 0) #C5C5FFFFFFFF0000 srgba(197,255,255,0)
1: (53199,65535,65535,65535) #CFCFFFFFFFFFFFFF srgba(207,255,255,1)
1: (53199,65535,65535, 0) #CFCFFFFFFFFF0000 srgba(207,255,255,0)
1: (53713, 514, 0, 0) #D1D1020200000000 srgba(209,2,0,0)
1: (61680,32639, 514, 0) #F0F07F7F02020000 srgba(240,127,2,0)
1: (62194,65535,65535,48059) #F2F2FFFFFFFFBBBB srgba(242,255,255,0.733333)
1: (63222, 4626, 0,17476) #F6F6121200004444 srgba(246,18,0,0.266667)
1: (63479, 7967, 0,65535) #F7F71F1F0000FFFF srgba(247,31,0,1)
1: (64250,65535,65535, 0) #FAFAFFFFFFFF0000 srgba(250,255,255,0)
2: (65535, 0, 0,65535) #FFFF00000000FFFF red
2: (65535, 0, 0, 0) #FFFF000000000000 srgba(255,0,0,0)
1: (65535, 1542, 0, 0) #FFFF060600000000 srgba(255,6,0,0)
1: (65535,10023, 0, 0) #FFFF272700000000 srgba(255,39,0,0)
1: (65535,14649, 0, 0) #FFFF393900000000 srgba(255,57,0,0)
1: (65535,20560, 0, 0) #FFFF505000000000 srgba(255,80,0,0)
1: (65535,22873, 0, 0) #FFFF595900000000 srgba(255,89,0,0)
1: (65535,31354, 0,48059) #FFFF7A7A0000BBBB srgba(255,122,0,0.733333)
1: (65535,32896, 0, 0) #FFFF808000000000 srgba(255,128,0,0)
1: (65535,33924, 0,65535) #FFFF84840000FFFF srgba(255,132,0,1)
1: (65535,36751, 0,65535) #FFFF8F8F0000FFFF srgba(255,143,0,1)
1: (65535,36751, 0, 0) #FFFF8F8F00000000 srgba(255,143,0,0)
1: (65535,41634, 1285, 0) #FFFFA2A205050000 srgba(255,162,5,0)
1: (65535,51400, 2056, 0) #FFFFC8C808080000 srgba(255,200,8,0)
1: (65535,51657, 1285, 0) #FFFFC9C905050000 srgba(255,201,5,0)
1: (65535,52428, 0,65535) #FFFFCCCC0000FFFF srgba(255,204,0,1)
2: (65535,53199, 0, 0) #FFFFCFCF00000000 srgba(255,207,0,0)
1: (65535,56797, 0, 0) #FFFFDDDD00000000 srgba(255,221,0,0)
1: (65535,63993,60652, 0) #FFFFF9F9ECEC0000 srgba(255,249,236,0)
1: (65535,64764,30583, 0) #FFFFFCFC77770000 srgba(255,252,119,0)
1: (65535,65535, 0,17476) #FFFFFFFF00004444 srgba(255,255,0,0.266667)
1: (65535,65535,10794,65535) #FFFFFFFF2A2AFFFF srgba(255,255,42,1)
1: (65535,65535,19018, 0) #FFFFFFFF4A4A0000 srgba(255,255,74,0)
4: (65535,65535,24415,65535) #FFFFFFFF5F5FFFFF srgba(255,255,95,1)
1: (65535,65535,33410, 0) #FFFFFFFF82820000 srgba(255,255,130,0)
1: (65535,65535,35980, 0) #FFFFFFFF8C8C0000 srgba(255,255,140,0)
1: (65535,65535,40349, 0) #FFFFFFFF9D9D0000 srgba(255,255,157,0)
1: (65535,65535,46774, 0) #FFFFFFFFB6B60000 srgba(255,255,182,0)
1: (65535,65535,50372,65535) #FFFFFFFFC4C4FFFF srgba(255,255,196,1)
1: (65535,65535,57825, 0) #FFFFFFFFE1E10000 srgba(255,255,225,0)
1: (65535,65535,58853, 0) #FFFFFFFFE5E50000 srgba(255,255,229,0)
1: (65535,65535,60909,65535) #FFFFFFFFEDEDFFFF srgba(255,255,237,1)
1: (65535,65535,63222,65535) #FFFFFFFFF6F6FFFF srgba(255,255,246,1)
81004: (65535,65535,65535, 0) #FFFFFFFFFFFF0000 srgba(255,255,255,0)
15: (65535,65535,65535,65535) #FFFFFFFFFFFFFFFF white
1: (65535,65535,65535,48059) #FFFFFFFFFFFFBBBB srgba(255,255,255,0.733333)
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 283x425+0+0
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Properties:
date:create: 2020-07-09T10:19:20+00:00
date:modify: 2020-07-09T10:19:20+00:00
icc:copyright: Copyright Artifex Software 2011
icc:description: Artifex Software sRGB ICC Profile
pdf:HiResBoundingBox: 283.44x425.28+0+0
pdf:Version: PDF-1.7
signature: 461f6c5fdc9ba4add29d8e3cdc3848d42d43c56f5603352e5c2e462256bf6dfc
Profiles:
Profile-icc: 2576 bytes
Artifacts:
filename: 1160914_a.pdf
verbose: true
Tainted: False
Filesize: 8609B
Number pixels: 120275
Pixels per second: 70.6639MB
User time: 0.000u
Elapsed time: 0:01.001
Version: ImageMagick 6.9.10-68 Q16 x86_64 2020-04-01 https://imagemagick.org

I have run into the same issue and I found a solution.
Use the -strip switch when creating the PDF using convert.
This fixed the issue for me.

Ghostscript is telling you that the PDF declaration of the ICC profile doesn't match the content of the profile.
An ICC profile colour space declaration in a PDF file contains a key /N whose value is the number of components in the output space. So for an RGB profile it will be 3, for a CMYK profile it will be 4. The ICC profile itself carries more information, but it also declares what the output colour space actually is. If the number of components in the ICC profile doesn't match the /N value in the PDF file, then Ghostscript tells you.
Annotating a PDF file changes it, so my guess is that you annotation software broke something. Without seeing the file I cannot tell for certain.
In order to investigate it you can run Ghostscript with -dPDFDEBUG and look at the PDF debug stream. When you see the complaint about the profile, note the object that was being interpreted. Then open the PDF file with an editor, look for that object and check the /N value of the ICCBased colour space against the content of the ICC profile. You can also try setting -dPDFSTOPONERROR which should cause Ghostscript to stop when it encounters the problem, making it easier to determine what is causing the problem.
You then need to check the files before you annotated them and afterwards. To be honest, unless you are familiar with the PDF specification this is going to take you quite a while and possibly be quite difficult.
I've no idea what IM is doing with that command

Related

how to parse strings from a file?

I have a text file.
each block parameter is separated by a colon
WoodBlock : 0.886275, 0.607843, 0.25098 : 2, 2, 2 : true : -75.5656891, -11.899992, -416.506866, 1, 0, 0, 0, 1, 0, 0, 0, 1 : 0, 0, 0 : 0, 0, 0
RustedBlock : 0.639216, 0.635294, 0.647059 : 2, 2, 2 : true : -35.5656891, -11.899992, -424.506866, 1, 0, 0, 0, 1, 0, 0, 0, 1 : 0, 0, 0 : 0, 0, 0
StoneBlock : 0.639216, 0.635294, 0.647059 : 2, 2, 2 : true : -50.5656891, -11.899992, -425.506866, 1, 0, 0, 0, 1, 0, 0, 0, 1 : 0, 0, 0 : 0, 0, 0
MetalRod : 0.388235, 0.372549, 0.384314 : 1, 3, 1 : true : -51.5656891, -11.399992, -412.506866, 1, 0, 0, 0, 1, 0, 0, 0, 1 : 0, 0, 0 : 0, 0, 0
Each line contains information about a block. I want to make an algorithm that will work like this:
the first line is selected
the second parameter of the line is selected - the script does something with this parameter
the third parameter of the line is selected - the script does something with this parameter
the fourth parameter of the line is selected - the script does something with this parameter
select the fifth parameter of the line - the script does something with this parameter
etc.
I tried using gsub but I don't know how I can select a certain line or parameter in it
You can use string.gmatch to match all parameters in the colon-delimited string. The pattern used to indicate the separator is [^:]+, which translates to "match everything but : (a colon)".
Here's an example script that loops over each line, then prints each parameter.
for line in io.lines("blocks.txt") do
for param in string.gmatch(line, "[^:]+") do
print(param)
end
end

Metadict in ffmpeg does not have rotate information

My aim is to extract frames out of a video but many times the frames are inverted. This is happening because "VideoCapture" in cv2 does read the rotate flag data present in the video metadata. I am running it on mac and installed "ffmpeg" package (5.0.1) using brew package manager. This is my code to check rotation present in a video using ffmpeg.
import ffmpeg
import cv2
import pprint
pp = pprint.PrettyPrinter(depth=4)
def check_rotation(path_video_file):
# this returns meta-data of the video file in form of a dictionary
meta_dict = ffmpeg.probe(path_video_file)
pp.pprint(meta_dict)
# from the dictionary, meta_dict['streams'][0]['tags']['rotate'] is the key
# we are looking for
rotateCode = None
if int(meta_dict['streams'][0]['tags']['rotate']) == 90:
rotateCode = cv2.ROTATE_90_CLOCKWISE
elif int(meta_dict['streams'][0]['tags']['rotate']) == 180:
rotateCode = cv2.ROTATE_180
elif int(meta_dict['streams'][0]['tags']['rotate']) == 270:
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE
return rotateCode
Here the meta_dict is supposed to have information about the rotation but it is not there.
printing out meta_dict gives:
{'format': {'bit_rate': '18498544',
'duration': '3.584000',
'filename': 'video.mp4',
'format_long_name': 'QuickTime / MOV',
'format_name': 'mov,mp4,m4a,3gp,3g2,mj2',
'nb_programs': 0,
'nb_streams': 2,
'probe_score': 100,
'size': '8287348',
'start_time': '0.000000',
'tags': {'com.android.version': '11',
'compatible_brands': 'isommp42',
'creation_time': '2021-12-08T10:56:57.000000Z',
'major_brand': 'mp42',
'minor_version': '0'}},
'streams': [{'avg_frame_rate': '990000/34997',
'bit_rate': '18804651',
'bits_per_raw_sample': '8',
'chroma_location': 'left',
'closed_captions': 0,
'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
'codec_name': 'h264',
'codec_tag': '0x31637661',
'codec_tag_string': 'avc1',
'codec_type': 'video',
'coded_height': 1080,
'coded_width': 1920,
'color_primaries': 'bt470bg',
'color_range': 'pc',
'color_space': 'bt470bg',
'color_transfer': 'smpte170m',
'display_aspect_ratio': '16:9',
'disposition': {'attached_pic': 0,
'captions': 0,
'clean_effects': 0,
'comment': 0,
'default': 1,
'dependent': 0,
'descriptions': 0,
'dub': 0,
'forced': 0,
'hearing_impaired': 0,
'karaoke': 0,
'lyrics': 0,
'metadata': 0,
'original': 0,
'still_image': 0,
'timed_thumbnails': 0,
'visual_impaired': 0},
'duration': '3.499700',
'duration_ts': 314973,
'extradata_size': 35,
'field_order': 'progressive',
'film_grain': 0,
'has_b_frames': 0,
'height': 1080,
'id': '0x1',
'index': 0,
'is_avc': 'true',
'level': 40,
'nal_length_size': '4',
'nb_frames': '99',
'pix_fmt': 'yuvj420p',
'profile': 'High',
'r_frame_rate': '120/1',
'refs': 1,
'sample_aspect_ratio': '1:1',
'side_data_list': [{...}],
'start_pts': 3168,
'start_time': '0.035200',
'tags': {'creation_time': '2021-12-08T10:56:57.000000Z',
'handler_name': 'VideoHandle',
'language': 'eng',
'vendor_id': '[0][0][0][0]'},
'time_base': '1/90000',
'width': 1920},
{'avg_frame_rate': '0/0',
'bit_rate': '128986',
'bits_per_sample': 0,
'channel_layout': 'stereo',
'channels': 2,
'codec_long_name': 'AAC (Advanced Audio Coding)',
'codec_name': 'aac',
'codec_tag': '0x6134706d',
'codec_tag_string': 'mp4a',
'codec_type': 'audio',
'disposition': {'attached_pic': 0,
'captions': 0,
'clean_effects': 0,
'comment': 0,
'default': 1,
'dependent': 0,
'descriptions': 0,
'dub': 0,
'forced': 0,
'hearing_impaired': 0,
'karaoke': 0,
'lyrics': 0,
'metadata': 0,
'original': 0,
'still_image': 0,
'timed_thumbnails': 0,
'visual_impaired': 0},
'duration': '3.584000',
'duration_ts': 172032,
'extradata_size': 2,
'id': '0x2',
'index': 1,
'nb_frames': '168',
'profile': 'LC',
'r_frame_rate': '0/0',
'sample_fmt': 'fltp',
'sample_rate': '48000',
'start_pts': 0,
'start_time': '0.000000',
'tags': {'creation_time': '2021-12-08T10:56:57.000000Z',
'handler_name': 'SoundHandle',
'language': 'eng',
'vendor_id': '[0][0][0][0]'},
'time_base': '1/48000'}]}
Can someone please help me to find if rotation is present in a video?

Love2d / LUA grid locked movement NO DIAGONAL

I thought this would be a common problem but after days of research I can't find a solution. Very new to programming in general and LUA specifically. I'm building a SUPAPLEX clone as a CS50 personal project: the character moves along the grid based map and there's a code that everyone seems to suggest (attached). On release of arrow buttons the movement is continued until the end of a tile, smoothly. But if 2 movement buttons are pushed, it causes brief diagonal movement and that's the problem I'm unsuccessfully trying to solve.
Basically I'm trying to either ignore any input until the movement of the sprite is finished at the end of the grid tile or prevent updating until movement in one direction is complete. Seems like a simple thing but I'm about to give up this whole thing. Frustrating. Any input is hiiiighly appreciated and I'm sure this would be a lot of help for very many people...
function love.load()
love.keyboard.setKeyRepeat(true)
player = {
grid_x = 256,
grid_y = 256,
act_x = 256,
act_y = 256,
speed = 5,
}
map = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
}
function testMap(x, y)
if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then
return false
end
return true
end
function love.keypressed(key)
if key == "up" then
player.grid_y = player.grid_y - 32
elseif key == "down" then
player.grid_y = player.grid_y + 32
elseif key == "left" then
player.grid_x = player.grid_x - 32
elseif key == "right" then
player.grid_x = player.grid_x + 32
end
end
end
function love.update(dt)
player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end
function love.draw()
love.graphics.rectangle("fill", player.act_x, player.act_y, 32, 32)
for y=1, #map do
for x=1, #map[y] do
if map[y][x] == 1 then
love.graphics.rectangle("line", x * 32, y * 32, 32, 32)
end
end
end
end
you're trying to get it to only walk along grid-lines?
take out love.keyboard.setKeyRepeat(true)
and don't use love.keypressed(key)
that's for one-at-a-time keypresses, and it would be hard to use that
with love.keyreleased() to see if all the other keys are released.
use isDown instead, and if one of them isDown, then none of the other dir keys allow input. (along with the couple player.act lines you already have in your update)
player = {
grid_x = 256,
grid_y = 256,
act_x = 256,
act_y = 256,
speed = 5,
dir = ''
}
function love.update(dt)
if love.keyboard.isDown("up", "down", "left", "right") then
if love.keyboard.isDown("up") and ( player.dir == 'up' or player.dir == '' ) then
player.dir = 'up' -- only go up if currently held, or no other dir key being pressed
player.grid_y = player.grid_y - 32
elseif love.keyboard.isDown("down") and ( player.dir == 'down' or player.dir == '' ) then
player.dir = 'down' -- only go down if currently held...
player.grid_y = player.grid_y + 32
elseif key == "left" and ( player.dir == 'left' or player.dir == '' ) then
player.dir = 'left'
player.grid_x = player.grid_x - 32
elseif key == "right" and ( player.dir == 'right' or player.dir == '' ) then
player.dir = 'right'
player.grid_x = player.grid_x + 32
end
else -- none of those keys are being pressed, so player is idle
player.dir = ''
end -- isDown()
player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end -- update()

Client request for tensorflow serving gives error "Attempting to use uninitialized value fully_connected/biases"

I created a LSTM RNN model for text classification on tensorflow and exported the savedModel successfully. I tested the model using savedModel CLI and everything seems to be working fine. However I am trying to create a client that can make a request and get a result. I have been following this tensorflow serving inception example (more specifically inception_client.py) for reference. This works well with the inception model but I am not sure how to change the request for my own model. How exactly should I change the request?
My signature and saving the model:
# Build the signature_def_map.
classification_signature = signature_def_utils.build_signature_def(
inputs={signature_constants.CLASSIFY_INPUTS: classification_inputs},
outputs={
signature_constants.CLASSIFY_OUTPUT_CLASSES:
classification_outputs_classes,
},
method_name=signature_constants.CLASSIFY_METHOD_NAME)
legacy_init_op = tf.group(
tf.tables_initializer(), name='legacy_init_op')
#add the sigs to the servable
builder.add_meta_graph_and_variables(
sess, [tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
classification_signature
},
assets_collection=tf.get_collection(tf.GraphKeys.ASSET_FILEPATHS),
legacy_init_op=tf.group(assign_filename_op))
print ("added meta graph and variables")
builder.save()
print("model saved")
The model takes in inputs_ as the input which is a list of list of numbers ( [[1,3,4,5,2]] ).
inputs_ = tf.placeholder(tf.int32, [None, None], name="input_ints")
How I am using the savedModel CLI (returns right results):
$ saved_model_cli run --dir ./python2_SavedModelFinalInputInts --tag_set serve --signature_def 'serving_default' --input_exprs inputs='[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2634, 758, 938, 579, 1868, 1894, 24, 651, 572, 32, 1847, 232]]'
More information about the savedModel:
$ saved_model_cli show --dir ./python2_prediction_SavedModelFinalInputInts --all
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:
signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['inputs'] tensor_info:
dtype: DT_INT32
shape: (-1, -1)
name: inputs/input_ints:0
The given SavedModel SignatureDef contains the following output(s):
outputs['outputs'] tensor_info:
dtype: DT_FLOAT
shape: (1, 1)
name: predictions/fully_connected/Sigmoid:0
Method name is: tensorflow/serving/predict
How I am trying to create a request in the client code:
request1 = predict_pb2.PredictRequest()
request1.model_spec.name = 'mnist'
request1.model_spec.signature_name = signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
request1.inputs[signature_constants.PREDICT_INPUTS].CopyFrom(tf.contrib.util.make_tensor_proto(input_nums, shape=[1,100],dtype=tf.int32))
response = stub.Predict(request1,1.0)
result_dict = { 'Analyst Rating': str(response.message) }
return jsonify(result_dict)
I am getting the following error:
[2017-11-29 19:03:29,318] ERROR in app: Exception on /analyst_rating [POST]
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 480, in wrapper
resp = resource(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 595, in dispatch_request
resp = meth(*args, **kwargs)
File "restApi.py", line 91, in post
response = stub.Predict(request,1)
File "/usr/local/lib/python2.7/dist-packages/grpc/beta/_client_adaptations.py", line 309, in __call__
self._request_serializer, self._response_deserializer)
File "/usr/local/lib/python2.7/dist-packages/grpc/beta/_client_adaptations.py", line 195, in _blocking_unary_unary
raise _abortion_error(rpc_error_call)
AbortionError: AbortionError(code=StatusCode.FAILED_PRECONDITION, details="Attempting to use uninitialized value fully_connected/biases
[[Node: fully_connected/biases/read = Identity[T=DT_FLOAT, _class=["loc:#fully_connected/biases"], _output_shapes=[[1]], _device="/job:localhost/replica:0/task:0/cpu:0"](fully_connected/biases)]]")
127.0.0.1 - - [29/Nov/2017 19:03:29] "POST /analyst_rating HTTP/1.1" 500 -
{"message": "Internal Server Error"}
Update:
Changing the signature of the model from a classification signature to a prediction signature seemed to work. I also changed the legacy_init_op to legacy_init_op as defined from assign_filename_op which I was using for Assets organization initially.
Changing the model signature from classification to a prediction signature seemed to return results.
prediction_signature = (tf.saved_model.signature_def_utils.build_signature_def(
inputs={signature_constants.PREDICT_INPUTS: prediction_inputs},
outputs={signature_constants.PREDICT_OUTPUTS: prediction_outputs},
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME))
legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')
#add the sigs to the servable
builder.add_meta_graph_and_variables(
sess, [tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
prediction_signature
},
# assets_collection=tf.get_collection(tf.GraphKeys.ASSET_FILEPATHS),
legacy_init_op=legacy_init_op)
I am not entirely sure how the client request should be for a model with classification signature or why it was not working.
(If anyone has an explanation, I will select that as the correct answer.)

gawk: change 5th element on every other line

I want to add a line break (\n) in front of the 5th element on every other line:
2, 0, 0, 0, 2
4, 0, 0, 0, 4
6, 0, 0, 0, 6
8, 0, 0, 0, 8
... in order to get:
2, 0, 0, 0, 2
4, 0, 0, 0, \n4
6, 0, 0, 0, 6
8, 0, 0, 0, \n8
What I have so far in gawk doesn't work:
gawk '{if (NR % 2) {$5=\n$5; print} else print}'
You could say:
awk '{NR%2 || $5="\\n"$5 }1' filename
Note that you'll need to escape the \ in order to get a literal \.
For your input, it'd produce:
2, 0, 0, 0, 2
4, 0, 0, 0, \n4
6, 0, 0, 0, 6
8, 0, 0, 0, \n8
Alternatively, (as pointed out by #WilliamPursell), you could say:
awk '!(NR%2) {$5="\\n"$5 }1' filename

Resources