-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed problems when decimal shifts != 0 #2887
base: main
Are you sure you want to change the base?
Conversation
The main reason was a wrong digital / analog sync, if decimal shifts were != 0. Also fixed hanging digits for late transition, which happened at my own installation only. Also reverted back to the improved unit test system of Slider0007, which seemed to be mistakenly overwritten by someone.
@rainman110: That's great for the affected users you figured it out :-) General questions/remarks (without any rating):
Further questions (just for my understanding as I want to integrate the new test cases in my environment with derived 'old' logic as well):
Why do you want that hanging digit is getting corrected although analog value is already higher than threshold? As for my understanding, either digit arrrived too early at 1.9 which means it should be kept at 1 until analog also crosses zero or it's a hanging digit from last cycle then 'a2dt' threshold might be higher, because not such an early compensation would be needed. What's my mistake?
Why is the expected result 13.x and not 12.x?
Why is the expected result 12.x instead 11.x? Also some of the following in same function I do not understand. It seems your meter needs to be read 1 higher all the time versus what it's states or I'm totally wrong!? Sorry for all those questions... |
Dear @Slider0007 . First thank you for a great in depth code review. In fact, I had the impression, that my previous PR was merged too early without a proper code review. Let my try to answer your questions:
Yes this is true and unfortunate. In fact, since I am new to the project, I could not completely understand the old logic and I started implementing my own - for myself and my problem of late transitioning, which was not addressed before. I would rather favour, if we can combine the old and new code.
The old logic is practically disabled in line AI-on-the-edge-device/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp Line 937 in b31a613
by using
Yes! And you obviously can judge this. I did not want to change to much old code - since I could not completely understand it. I would be happier, if we just had one algo. As I said, I hoped at that this was addressed at the first PR, when this was merged without a review (see #2778)
Lets look at "my actual issue" back then: #2743 This is what I understand as late transitioning. In this case, the last digit transitions too late, i.e. when the analog value is at about ~3.5. This means, when the analog value is in the range of 0 ... 3.5, the last digit 1 too small. It's basically the inverse of early transition. Support for late transition was IMHO not implemented before this PR. How do I differentiate between early and late? Late means, that the digit transitions between analog values of 0.5 ... 5. Early transition means, that the digit transitions between analog value 5 ... 9.5. Normal transition would be 9.5 ... 0.5. In fact, my new code seems to be using different values than the old... which is not intentional. Please let me know, how we can improve the situation.
Normally , nothing need to be done, when the value is higher than threshold. But in this test case, the last digit still hangs at 1.9 (so 1 would be used). After transition, it should be 2.0 though. Hence it needs to be corrected. Don't ask me, how often I needed to wrap my head around this. This problem seems to be so easy on first sight, but the more I think about it, the weirder it gets 😆 . I derived these test cases from my own device, which has these problems. So the tests should be correct ;)
Excellent questions. In this case, we have a hanging digit and late transition. First lets assume the last digit would be not hanging, i.e. The first analog (1.2) is still smaller than the transition value (3.6). Ideally, the 2.0 would have been transitioned to 3.0 at analog = 0. Since we have late transitioning, the transition has not happened, so we need to correct for it to 3.0. Now we have a hanging digit of 1.9. So we have to correct twice, from 1 -> 2 (hanging) and from 2-> 3(late transition). I hope, the explanation is clear?
The same explanation as above, but without hanging digit. The transition should have happened already, but did not due to the late transition issue. How do we now proceed? Ideally, since you know the code much better than me, I'd prefer if we could use your? old code as a basis and modify it, to make my new unittests (*lateTransition) working. You can assume, that the tests are correct 😏 Let me know, how we proceed. |
@Slider0007 If I also might ask, how do you develop / debug the code? I have a not-so-nice setup to be able to cross-compile the code to PC and debug it. I hoped, there would be a way to simply build for esp32 and let the tests run in an emulator or so. Is there any way to do it? |
@rainman110:
I think this is the point where you interprete it different or at least you name it differently :-) At least for me the digit is almost reaching the 2 although analog is still quite low -> EARLY digit based on this interpretation https://jomjol.github.io/AI-on-the-edge-device-docs/Watermeter-specific-analog---digital-transition/. My explanation: Your digit is getting quite early to region of 2. This early situation is not covered by firmware's 'old' logic, therefore after digit reaches the digit zero crossing uncertainty area (>= x.8 due to e.g. mechanical sync tolerances, alignment or model uncertainties), algo unfortunately prioritize 'hanging digits' handling (analog value <= AnalogDigitTransitionStart - which was limited to lowest of 6) over 'too early arrived digits' handling (analog value > AnalogDigitTransitionStart). Value gets corrected upwards and you got the jump in reading -> not desired. In your case 'do nothing' would be the expected reaction until analog also reaches zero crossing.
Ah ok, I didn't realized this small change during my quick check ;-) Unfortunately, AnalogDigitTransitionStart=0 does NOT turn off sync behaviour. It's still partly active.
For me it's the same case than your initial case which means keep value until analog has zero crossing. Can you provide an screenshot for better understanding?
Analog has zero crossing, digit is hanging -> therefore correct it upwards +1: 11.x --> 12.x Can you provide an screenshot for better understanding? If you are interested I can provide upfront a test version of my private copy with extended AnalogDigitTransitionStart range down to 3 and old logic supporting it for initial testing purpose (be aware: It's without any of your code and has sightly different REST / MQTT APIs). Your test case is already included. If this the right direction and I did it correctly we could continue this way. @haverland, @jomjol: From my point of view it should be possible to add this early digit situation to existing algo as far as I can see this from my limited perspective. All other test cases still work. Porting back to this firmware should be feasible. |
Sorry, I do not have any special environment in place, just a spare ESP32CAM board hooked up to PC. |
Here's a screenshot. Note, the digit 8 is hanging (7.9) and the transition has not started yet: The correct value (in my current interpretation) is 419.2579. And now to the interpretation. Sure, one can discuss,if this is also a case of very early transition. But what if the transition starts even earlier,let's say at 0.5 . Is this then extremely early or just a little late? Just handling everything as early has though the charme of just using one algorithm compared to two.
What do you mean? What cannot be ported back? |
As preview, evaluation of late transition test cases with extended old logic:
Result Algo: 11.0210
Result Algo: 11.3210
Result Algo: 12.4210
Result Algo: 12.9870
Result Algo: 12.003
Result Algo: 13.351
Result Algo: 13.421 Three of them differs from your expectation. |
To understand the test cases. These tests simulate are real 1000 liter Simulation. So it just starts shortly after 12 and ends at 13. All tests are in the correct sequence as they appear on my device. Hence, all resulting numbers need to be in ascending order. Whether they are all 1000 liters less, I don't care. But they obviously should not oscillate. If you implement using too early transition, all digits need to be corrected -1, after the analog values is larger than 3.6 basically. |
If the analog value is 200 liter more, the digit had transitioned and it would show 419,4 right? So it must have been 419,2 (and not 418,2) earlier, otherwise 1200 liters would have flown. |
The only one which is not in ascending order is this one:
Are you sure that the lowest digit is sure 2.0 and not maybe 2.8 - 3.x?
Just to make it clear, this is the actual implementation right now, before your change, only limited to not lower than 6.0 because jomjol or haverland haven't forseen such an early entry. I more or less just lowered the value to 3 and did not implement anything else for detection. |
No, 200 liter are 200 liter :-) Your digit transition started but it's still 418.x, in this case 418.4x. Switch to real 419 can only happen if analog has next zero crossing. |
Your values are wrong, since they cover more than 2000 liters, but the simulation is just over 1000 liters. The jump from 11.3 to 12.4 is wrong. It was actually just 100 liters in between, but the digit changed from 1 to 2 in these 100 liters. |
I try to provide you a full real 1000 liter cycle of my device. It is wierder than you think ;) |
For the actual value yes! The device no. So either you interpret both value as 11.3 and 11.4 ,or 12.3 and 12.4. your tests though give 11.3 and then 12.4 |
OK, could be. Just copied your test cases as is.
That's the funny thing. With test cases you can get everything you want if you'd like to, just by trimming to the corect input values. But I think that's not the goal ;-)
What kind of meter do you have!? ;-) To makes it easier for me I try to prepare I test version with AnanlogDigitTransitionStart lowered to 3 from a commit before your code got merged. So you could test and compare by yourself. Have a good night. I'm out for today... |
I think my meter is simply assembled incorrectly. Nevermind. Thanks for the discussion. Let's discuss it further in the next days. |
A last one for today: With slightly adapted values and a adaption of a2dt to 3.4 your ascending order is possible:
|
@rainman110: Related firmware build for direct download: https://github.com/jomjol/AI-on-the-edge-device/actions/runs/7866238026 Be aware: It's not based on latest rolling, but on last commit before merge of your alternative logic. Also added by later merged test case fixes from haverland and tflite heap fix. Goal: Figure out if this small change of the 'old' logic is sufficient to cover your meter which has a really early digit tranisition. |
Thank you..I am gonna try this out. Should we still merge this PR as a quick fix to close the issue for now and help them with problems regarding the decimal shift? |
In the meantime there are also some issues described with too low raw value where decimal shift is not set or set to 0!? Will this then be also fixed or just the situations where decimal shift is set !=0? |
@FrankCGN01 The digit classification does not work for your last digit, probably due to the line through the digits. Maybe try a different model. Otherwise, add these images to the training set. |
@rainman110 Some of the numbers with the line are already included in the known numbers. But the 8 with the dash is still missing. I will save the pictures in the next few days and then the missing numbers with the lines can be added to the model. |
@Slider0007 I suggest removing the failing test from @FrankCGN01 , since the inferred values are incorrect. This needs a model improvement instead. |
For me the example looks valid. Update:
Also this one is processed successfully with 'old logic'! Some special test cases seems to be handled better by your logic, but it fails in some basic real examples. There seems still lots of open topics... As long it's not clear why even those basic examples are not working anymore, we should in first step provide a stable firmware version. Even old logic is not fully cover all test edge cases. Therefore we decided to revert your logic to previous logic to have stable version again. Sorry! |
With this version (Development-Branch: HEAD (Commit: f4c4498+)) it works as it should at least for now. |
@caco3 and @Slider0007 I am still working on a more improved sync, but I think it will take same time. I could fix some of the failing test though already. I now stumbled upon one particular test, where I am not sure, which should be the correct expected value: Digits: 0.9, 4.8, 9.0, 3.0, 6.0, 5.0 My new algorithm returns 149364.9. In theory, with a normal meter, the last digit should be in in the range of 4.5 - 5.0, when the analog almost is at the top at zero. Otherwise, the meter would transition too late. What do you think is the correct value in your interpretations? @haverland What do you think? |
I think we should wait until @haverland also joins this discussioin. He has more history than me in this topic. |
Sorry for the late reply. Look at this test case. Maybe the same: AI-on-the-edge-device/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp Line 357 in d6a1838
And look at the diskussion about the test case. |
I've added a complete transition in function test_flowpostprocessing.cpp#test_doFlowPP_rainman110_transition(). @Slider0007 @rainman110 could you review the input and expected results? If it's ok for you, I can approve the pull request |
I was wondering where you added the changes because the related branch of this PR is unchanged. Then I realized you modified the following test branch: https://github.com/jomjol/AI-on-the-edge-device/tree/analog-digit-early-digit-test
All test cases would be green with this configuration. Any concerns? Be aware: With all the modifications the result of this new test case using our algo will be 149364.9 which is not aligned with your argumentation here: #2887 (comment) |
Sorry for the confusion. I hadn't realized that the branch https://github.com/jomjol/AI-on-the-edge-device/tree/analog-digit-early-digit-test is not connected to the PR. I first merged both branches from the current rolling. But the rainman110:fix_issue_2857 showed more errors, also in the rainman110 test cases. Therefore, I first added the additional test cases from rainman110:fix_issue_2857 to the analog-digit-early-digit-test. Now the analog-digit-early-digit-test also has 4 test cases that fail. |
@haverland: No problem :-) Thanks for merging latest rolling. I've just checked the 4 failing cases of branch https://github.com/jomjol/AI-on-the-edge-device/tree/analog-digit-early-digit-test. --> I commited my proposed changes for discussion. All tests are green with these changes. Please first check the remarks here.
TBD: It is a matter of interpretation, is it too late or is it quite early? Actual algo interprets as quite early and corrects value back.
If it should be valid hanging scenario my proposal is not valid. Algo is most likely not covering this, either correcting hanging or early transition, but not both. How do you interprete this?
{ 0.9, 4.8, 8.9, 3.0, ... -> 1 5 9 What is your opinion?
|
1.) No! Please not. Is the standard transition if digit and analog pointer transition fits. Means on 0.0 on analog pointer the digit is x.0. And a bit later the analog pointer is 0.2 and the digit x.0 until next transition after 9.2 on analog. 2.) I've added a case (or moved it up a few lines) for an analog pointer that transition is a bit earlier than the digit transition. Also often case.
3.) Shows an issue on every full digit transition. I've added the case with 1.0 (2nd test) it reduces the first digit. And creates shortly a real big negative rate or in case of 0099.5 a extremly high value. All after are now negatives
4.) is in my opinion the same issue like 3.) |
3.)/4.) I make a new branch/PR it's another issue and can fixed separately. |
@haverland: In this case I don't get it correctly. Please feel free to take over the topic and discard my proposal. |
I took another look at cases 3 and 4.
But because of the rounding over x.8 it rounds up to 5. So the value is correct. The lowest digit has a false recognition because of the line in the 8. Could be better if the ROI configuration is correct. |
But I'm struggling with case 1.) and 2.). To solve it for the case of very early (or very late) transition, it would always break the standard. The short late transition algo will set it shortly to the next digit and after x.2 the "hanging" digit values reduce it again until the real transition is coming. |
The main reason was a wrong digital / analog sync, if decimal shifts were != 0.
The fix is not beautiful - I temporally revert the decimal shift to make it easier to sync the analog and digital part.
At the end, it is applied again. It works though.
I also fixed hanging digits for late transition, which happened at my own installation only.
Also reverted back to the improved unit test system of @Slider0007, which seemed to be mistakenly overwritten by someone.
Fixed #2857 and Discussion #2243
@Slider0007 Please have a look, in particular at
test_suite_flowcontroll.cpp
. I went back to your testing setup. Not sure, why it was the old code again?!