-
Notifications
You must be signed in to change notification settings - Fork 150
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
First try at saving/loading records from pickle #504
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks great! Exactly what we discussed in the issue!
One test is failing because a parser is being used twice and the cache is being loaded while the data changed, all we have to do is pass use_cached=False
to it. You can fix that if you want or I can fix it before mergining.
Just one more request before we merge this, can you write a simple test checking the pickle file was saved correctly? I understand creating tests can be hard at first but I'll help with everything I can.
Go to tests/parsers/test_parser.py
and you will find the function test_parser
, at the end of the asserts add a new check to verify the pickle file exists. Additionaly you can load the pickle file and assert it has the same contents as records
I wanted to check which one you were referring to as all tests were passing for me locally (I mean
Is this what you are referring to? |
hahahah that was not the one, for some reason that is not happening on the CI, you can check the full run here __________________________ test_voc_annotation_parser __________________________
samples_source = Path('/home/runner/work/icevision/icevision/samples')
voc_class_map = <ClassMap: {'background': 0, 'aeroplane': 1, 'bicycle': 2, 'bird': 3, 'boat': 4, 'bottle': 5, 'bus': 6, 'car': 7, 'cat... 'horse': 13, 'motorbike': 14, 'person': 15, 'pottedplant': 16, 'sheep': 17, 'sofa': 18, 'train': 19, 'tvmonitor': 20}>
def test_voc_annotation_parser(samples_source, voc_class_map):
annotation_parser = parsers.voc(
annotations_dir=samples_source / "voc/Annotations",
images_dir=samples_source / "voc/JPEGImages",
class_map=voc_class_map,
)
records = annotation_parser.parse(data_splitter=SingleSplitSplitter())[0]
> assert len(records) == 2
E assert 4 == 2
E + where 4 = len([Record:\n - Image ID: 0\n - Filepath: /home/runner/work/icevision/icevision/samples/fridge/odFridgeObjects/images/10.jp...s: [2, 4]\n - BBoxes: [<BBox (xmin:56, ymin:148, xmax:209, ymax:514)>, <BBox (xmin:328, ymin:180, xmax:449, ymax:502)>]])
tests/parsers/test_voc_parsers.py:12: AssertionError |
Interesting! :D let me look into this. I might have declared victory too soon. |
Ok, so the awkward errors I refer to, occur when I run |
Btw, the screenshot above is already after adding the 2 asserts you requested to |
So, I think I found the culprit but I am still having a hard time figuring this out.
This monster is driven by this annoying pickle issue, which, tbh, I am not even sure I completely get. |
Maybe we can bring this to the attention of the community in Discord? |
Oh, I can help you with that! This was a new addition and still has to be documented, it's a hack for making a local object pickable. It would be easier to explain it in a call, are you available at any time in the next week?
Hah! Pickle it's then!!! Okay okay, I have some ideas, the easiest and less stresfull solution would be for us to jump into a call and take a look at this, as I said in the previous comment I can explain why we are doing this and what is the best way of handling what is happening. I think this is the only place on the library where some python black magic is happening, and it was just added last week (with the autofix) so it's still not documented, I was not expecting that this issue would stumble into that, sry =x |
Sure, let's do this! |
And no need to be sorry man! |
Nice! I'll message you on Discord tomorrow and we can find a common time =) |
I think I found the issue. |
Codecov Report
@@ Coverage Diff @@
## master #504 +/- ##
==========================================
+ Coverage 86.42% 86.63% +0.20%
==========================================
Files 91 91
Lines 2181 2184 +3
==========================================
+ Hits 1885 1892 +7
+ Misses 296 292 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright! This issue was way harder than I originally expected but after a lot of figuring it out I think we reached a very good solution!
The final requested change is just to use a temporary path to save the pickle file so it automatically gets deleted after the testing session is over. You can find more info about it here.
Also, be sure to add this do the CHANGELOG.md
into the Added
section, say parser.parse has a new cache_filepath
argument and point to this PR =)
tests/parsers/test_parser.py
Outdated
@@ -43,8 +43,9 @@ def bboxes(self, o) -> List[BBox]: | |||
|
|||
def test_parser(data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_parser(data): | |
def test_parser(data, tmpdir): |
tests/parsers/test_parser.py
Outdated
@@ -43,8 +43,9 @@ def bboxes(self, o) -> List[BBox]: | |||
|
|||
def test_parser(data): | |||
parser = SimpleParser(data) | |||
|
|||
cache_filepath = Path("simple_parser.pkl") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache_filepath = Path("simple_parser.pkl") | |
cache_filepath = Path(tmpdir / "simple_parser.pkl") |
Alright, perfect!! Here we go Francesco! Thanks a lot again ^^ |
So, I added
get_root_dir
todata_dir.py
but tests are failing because they cannot find the function.Am I screwing something up with the imports?