Blazeface predictions returning negative x coordinates - tensorflow.js

I have my own Typescript Blazeface version up and running. The predictions rectangle however does not show up on the video overlay canvas. Debugging shows that the x coordinates returned from the predictions are negative. Is this user error or some other subtle bug in my code?
The source code can be found in this Codepen:
https://codepen.io/g_debailly/pen/zYGQKOe
This is the predictions array:
[
{
"topLeft": [
-261.7025451660156,
218.29611206054688
],
"bottomRight": [
-429.23638916015625,
343.9468994140625
],
"landmarks": [
[
-309.3980703353882,
265.82969784736633
],
[
-374.39136600494385,
260.38822889328003
],
[
-341.75953893363476,
302.7327650785446
],
[
-344.2469654083252,
320.3148329257965
],
[
-280.4582414627075,
261.1372035741806
],
[
-415.7755718231201,
250.6269371509552
]
],
"probability": [
0.9908785223960876
]
}
]

I solved the problem by setting the argument const flipHorizontal = false in the call to model.estimateFaces().

Related

chart js error in next js site hosted on netlify [duplicate]

This question already has answers here:
Error "RangeError: minimumFractionDigits value is out of range" with ChartJS in Next.js app
(3 answers)
Closed 4 months ago.
everthing is working fine in development on my local machine,
but when I deploy my site to netlify, I get this wierd error in console.
the page data is gotten using getStaticProps function and then passed to the page as props.
here is how the data looks like
[
[ 17671, 19856, 37527 ], [ 4887, 5418, 10305 ],
[ 2803, 2303, 5106 ], [ 8617, 9403, 18020 ],
[ 12664, 15722, 28386 ], [ 4227, 3359, 7586 ],
[ 1371, 1545, 2916 ], [ 17526, 14297, 31823 ],
[ 6883, 4781, 11664 ], [ 9805, 10000, 19805 ],
[ 11068, 12888, 23956 ], [ 4570, 4722, 9292 ],
[ 15428, 17309, 32737 ], [ 3565, 3656, 7221 ],
[ 8750, 10443, 19193 ], [ 1771, 1432, 3203 ],
[ 8495, 9979, 18474 ], [ 288, 265, 553 ],
[ 21130, 19321, 40451 ], [ 6867, 6556, 13423 ],
[ 2656, 2092, 4748 ], [ 967, 656, 1623 ],
[ 4540, 4505, 9045 ], [ 7025, 7108, 14133 ],
[ 53134, 59829, 112963 ], [ 8640, 9028, 17668 ],
[ 6759, 7119, 13878 ], [ 28803, 31362, 60165 ],
[ 7346, 7630, 14976 ], [ 9771, 10963, 20734 ],
[ 15783, 17397, 33180 ], [ 9847, 9706, 19553 ],
[ 15154, 17577, 32731 ], [ 1056, 874, 1930 ],
[ 3260, 2476, 5736 ], [ 1488, 1424, 2912 ],
[ 1656, 1154, 2810 ]
]
it is an array of arrays of 3 numbers.
please how do I solve this?
You need to set swcMinify: false false in your next.confug.js. This is currently a bug in the swcMinifier and you will need to wait until they have fixed it before you can enable it again.

TypeORM - PostGIS use custom feature in query

I have a project where I need to check inside which municipalities a certain road is inside. In order to do so I check this using the ST_Intersects function provided by PostGIS.
The problem that I am facing is that I keep on getting errors when using the roads in the querybuilder of typeorm.
My first attempt gave me the following error QueryFailedError: ST_Intersects: Operation on mixed SRID geometries (MultiPolygon, 4326) != (LineString, 0) at new QueryFailedError:
const municipalities = await getConnection()
.getRepository(Municipality)
.createQueryBuilder('municipality')
.where('ST_Intersects(municipality.polygon, :lineString)', { lineString: feature.geometry })
.getQueryAndParameters()
Then I tried to fix this by setting the CRS of the Linestring using ST_SetSRID function that is also provided by PostGIS. But this gives me the following error QueryFailedError: function st_setsrid(unknown, integer) is not unique:
const municipalities = await getConnection()
.getRepository(Municipality)
.createQueryBuilder('municipality')
.where('ST_Intersects(municipality.polygon, ST_SetSRID(:lineString, 4326))', { lineString: feature.geometry })
.getMany()
I have also tried to transfer the Geojson object using ST_GeomFromGeoJSON function in PostGIS. But this gives me the following error: QueryFailedError: quoted object property name expected (at offset 1):
const municipalities = await getConnection()
.getRepository(Municipality)
.createQueryBuilder('municipality')
.where('ST_Intersects(municipality.polygon, ST_GeomFromGeoJSON(:lineString))', { lineString: feature.geometry.coordinates })
.getMany()
I have tried to see if the problem was when inserting the linestring into the query. I did this by using the getQueryAndParameters return function of typeorm:
[
'SELECT "municipality"."uuid" AS "municipality_uuid", "municipality"."name" AS "municipality_name", ST_AsGeoJSON("municipality"."polygon")::json AS "municipality_polygon" FROM "municipality" "municipality" WHERE ST_Intersects("municipality"."polygon", ST_SetSRID($1, 4326))',
[ { type: 'LineString', coordinates: [Array] } ]
A Linestring object in looks as follows:
{
type: 'LineString',
coordinates: [
[ 3.2188848, 51.1980164 ],
[ 3.2190236, 51.1981144 ],
[ 3.2190737, 51.1981991 ],
[ 3.2191065, 51.1982793 ],
[ 3.2191314, 51.1983772 ],
[ 3.2191128, 51.1984885 ],
[ 3.2192215, 51.1985207 ],
[ 3.2192447, 51.1985056 ],
[ 3.219269, 51.1985136 ],
[ 3.2193766, 51.1985571 ],
[ 3.2194258, 51.1985769 ],
[ 3.2194638, 51.198697 ],
[ 3.2195437, 51.1987221 ],
[ 3.2196618, 51.1987591 ],
[ 3.219529, 51.1989397 ],
[ 3.2195909, 51.1990766 ],
[ 3.2196759, 51.1992964 ],
[ 3.2197817, 51.1993408 ],
[ 3.2199103, 51.1992987 ],
[ 3.2204127, 51.1991677 ],
[ 3.2208458, 51.199056 ],
[ 3.2211454, 51.1989993 ],
[ 3.2217751, 51.1988675 ],
[ 3.2219908, 51.1988136 ],
[ 3.2223186, 51.1987693 ],
[ 3.2223696, 51.1987867 ],
[ 3.2223974, 51.1987845 ],
[ 3.2225339, 51.1987696 ],
[ 3.2230863, 51.1987062 ],
[ 3.2233638, 51.198683 ],
[ 3.2234618, 51.1986505 ],
[ 3.223517, 51.1986535 ],
[ 3.2235298, 51.1986528 ],
[ 3.2236432, 51.198651 ],
[ 3.2243337, 51.1986565 ],
[ 3.2244463, 51.198654 ],
[ 3.2245644, 51.1986568 ],
[ 3.2249334, 51.1986506 ],
[ 3.2249647, 51.1986493 ],
[ 3.2251107, 51.19867 ],
[ 3.225378, 51.1986779 ],
[ 3.2257131, 51.1987153 ],
[ 3.225936, 51.1987341 ]
]
}
I have found an answer. ST_GeomFromGeoJSON was indeed the wright function to use in order to inject a GeoJSON object into the query. But I had accidentally used the coordinates instead of the full GeoJSON object.
So the solution is:
const municipalities = await getConnection()
.getRepository(Municipality)
.createQueryBuilder('municipality')
.where('ST_Intersects(municipality.polygon, ST_GeomFromGeoJSON(:lineString))', { lineString: feature.geometry })
.getMany()

Convert the following array data as Json in react

I need to convert the following array data to Json in react.
I tried map method, but it is not the correct way. I need key value pair, so that i can pass it to server as json
[
[
"channel",
"s1"
],
[
"category",
"Account 1"
],
[
"accountAdministration",
"Partnership 1"
],
[
"partnershipAccounting",
"1 level Performance issues"
],
[
"requestCategory",
"Research"
],
[
"severity",
"Blocker"
],
[
"activationDate",
"2020-10-29T05:54:00.000Z"
],
[
"managerApproved",
true
]
]
Try using reduce and creating an object:
var arr = []; // your array
var data = arr.reduce((map, item) => {
map[item[0]] = item[1];
return map;
}, {});
The data object will be in the following format:
{
"accountAdministration": "Partnership 1",
"activationDate": "2020-10-29T05:54:00.000Z",
"category": "Account 1",
"channel": "s1",
...
}
Worked with
Object.fromEntries([
[
"channel",
"s1"
],
[
"category",
"Account 1"
],
[
"accountAdministration",
"Partnership 1"
],
[
"partnershipAccounting",
"1 level Performance issues"
],
[
"requestCategory",
"Research"
],
[
"severity",
"Blocker"
],
[
"activationDate",
"2020-10-29T05:54:00.000Z"
],
[
"managerApproved",
true
]
])

Reverse Array of coordinates in swift 4

I am trying to reverse an array of coordinates. I have this array:
[
[
9.211615025997162,
44.30419567985762
],
[
9.21164184808731,
44.30412081929745
],
[
9.21165257692337,
44.304053636662175
],
[
9.211606979370117,
44.3038789614507
],
[
9.211572110652924,
44.30381945658962
],
[
9.211539924144745,
44.30378874437967
],
[
9.211507737636566,
44.30376187118276
],
[
9.211564064025879,
44.30377530778277
],
[
9.211574792861937,
44.30374075651943
],
[
9.211574792861937,
44.30371388330059
],
[
9.211574792861937,
44.30369852717
],
[
9.21154797077179,
44.303665895379176
],
[
9.211513102054596,
44.303650539236024
],
[
9.211429953575134,
44.30358911462331
],
[
9.211349487304688,
44.30355840229286
],
[
9.211271703243256,
44.303537287556324
],
[
9.21117514371872,
44.30349505806051
],
[
9.211151003837585,
44.303473943301235
],
[
9.211126863956451,
44.30342979423452
],
[
9.211145639419556,
44.30339908182071
],
[
9.211183190345764,
44.303368369390846
],
[
9.211223423480988,
44.30331846165803
],
[
9.211242198944092,
44.30327623200479
],
[
9.211177825927734,
44.30325895622883
],
[
9.211030304431915,
44.303228243725634
],
[
9.210925698280334,
44.30321096793552
],
[
9.210874736309052,
44.303197531206386
],
[
9.210831820964813,
44.303197531206386
],
[
9.21075403690338,
44.303197531206386
],
[
9.21068161725998,
44.3031994507393
],
[
9.210577011108398,
44.3031994507393
],
[
9.210509955883026,
44.303207128870355
],
[
9.210440218448639,
44.303207128870355
],
[
9.210370481014252,
44.30322632419366
],
[
9.2102712392807,
44.30324743904202
],
[
9.210190773010254,
44.30328199059568
],
[
9.210112988948822,
44.30328391012582
],
[
9.210059344768524,
44.303297346835215
],
[
9.209954738616943,
44.30332422024474
],
[
9.209901094436646,
44.303339576473235
],
[
9.209868907928467,
44.303349174114
],
[
9.209858179092407,
44.30338372560779
],
[
9.209791123867035,
44.30340292087333
],
[
9.209697246551514,
44.30342595518367
],
[
9.209648966789246,
44.3034509090097
],
[
9.209606051445007,
44.30351809233474
],
[
9.209579229354858,
44.30355840229286
],
[
9.209581911563873,
44.3035852755829
],
[
9.209622144699097,
44.30355840229286
],
[
9.20967847108841,
44.30355648277167
],
[
9.209697246551514,
44.30354112659989
]
]
And I would like to reverse the coordinates, which are right now in Long-Lat to Lat-Long thus reversing the whole array or each item in the array would do the job here. I have been stuck trying to make it work, trying things like arrayOfCoords.reversed() and .reverse() to no avail. So how can I do this?
There may be a more elegant/efficient way to do this, but I'd look at using compactMap:
let testArray = [[1.123,2.22], [3.11, 4.0], [5.21, 6.19]]
print(testArray)
[[1.123, 2.22], [3.11, 4.0], [5.21, 6.19]]
let flippedElementArray = testArray.compactMap { $0.count > 1 ? [$0[1], $0[0]] : nil }
print(flippedElementArray)
[[2.22, 1.123], [4.0, 3.11], [6.19, 5.21]]
The $0.count > 1 check just makes sure you have at least 2 elements so you don't get a bounds error. If not, the closure returns nil for that element, which will be filtered out by compactMap. Otherwise, it returns a new array element consisting of the second element followed by the first element. All of those elements are stored in the final mapped array (flippedElementArray).
arrayOfCoords.map{ Array($0.reversed()) }
I'm assuming you want to reverse each coordinate pair, but keep the pairs themselves in the original order. Since you have an array of arrays, you have to do the operation on each sub-array separately. And reversed() returns a ReversedCollection instead of an Array so you have to re-initialize it into an array to use it properly.

How to parse JSON array in array Swift?

I'm trying to parse JSON which is like below:
"price": [
[
1539283140000,
6288.07
],
[
1539283440000,
6285.82
],
[
1539283740000,
6285.81
],
[
1539284041000,
6280.37
],
[
1539284340000,
6280.19
]
Please help me deal with this. And is there a possibility to decode the timestamp value to a date.
Correct json
{
"price": [
[
1539283140000,
6288.07
],
[
1539283440000,
6285.82
],
[
1539283740000,
6285.81
],
[
1539284041000,
6280.37
],
[
1539284340000,
6280.19
]
]
}
struct Root: Codable {
let price: [[Double]]
}
let res = try? JSONDecodable().decode(Root.self,from:jsonData)

Resources