@@ -173,85 +173,94 @@ def test_filter_instances(tmpdir):
173173 # print(not_filtered[not_filtered["className"] == "Human
174174
175175
176- # def test_df_to_annotations(tmpdir):
177- # tmpdir = Path(tmpdir)
178-
179- # df = sa.aggregate_annotations_as_df(PROJECT_DIR)
180- # sa.df_to_annotations(df, tmpdir)
181- # df_new = sa.aggregate_annotations_as_df(tmpdir)
182-
183- # print(df_new["imageName"].value_counts())
184- # print(df["imageName"].value_counts())
185-
186- # for _index, row in enumerate(df.iterrows()):
187- # for _, row_2 in enumerate(df_new.iterrows()):
188- # if row_2[1].equals(row[1]):
189- # break
190- # else:
191- # assert False
192- # for project in sa.search_projects("test df to annotations 2"):
193- # sa.delete_project(project)
194- # project = sa.create_project("test df to annotations 2", "test", "Vector")
195- # sa.upload_images_from_folder_to_project(
196- # project, "./tests/sample_project_vector"
197- # )
198- # sa.create_annotation_classes_from_classes_json(
199- # project, "./tests/sample_project_vector/classes/classes.json"
200- # )
201- # sa.upload_annotations_from_folder_to_project(
202- # project, "./tests/sample_project_vector"
203- # )
204-
205- # def test_df_to_annotations_full(tmpdir):
206- # tmpdir = Path(tmpdir)
207-
208- # df = sa.aggregate_annotations_as_df(
209- # PROJECT_DIR, include_classes_wo_annotations=True, include_comments=True
210- # )
211- # sa.df_to_annotations(df, tmpdir)
212- # df_new = sa.aggregate_annotations_as_df(
213- # tmpdir, include_classes_wo_annotations=True, include_comments=True
214- # )
215- # for project in sa.search_projects("test df to annotations 4"):
216- # sa.delete_project(project)
217- # project = sa.create_project("test df to annotations 4", "test", "Vector")
218- # sa.upload_images_from_folder_to_project(project, PROJECT_DIR)
219- # sa.create_annotation_classes_from_classes_json(
220- # project, tmpdir / "classes" / "classes.json"
221- # )
222- # sa.upload_annotations_from_folder_to_project(project, tmpdir)
223- # # print(df_new["image_name"].value_counts())
224- # # print(df["image_name"].value_counts())
225- # for _index, row in enumerate(df.iterrows()):
226- # for _, row_2 in enumerate(df_new.iterrows()):
227- # if row_2[1].equals(row[1]):
228- # break
229- # else:
230- # assert False
231-
232- # fil1 = sa.filter_annotation_instances(
233- # df_new,
234- # include=[
235- # {
236- # "className": "Personal vehicle",
237- # "attributes": [{
238- # "name": "4",
239- # "groupName": "Num doors"
240- # }]
241- # }
242- # ],
243- # exclude=[{
244- # "type": "polygon"
245- # }]
246- # )
247- # filtered_export = (tmpdir / "filtered")
248- # filtered_export.mkdir()
249- # sa.df_to_annotations(fil1, filtered_export)
250- # for project in sa.search_projects("test df to annotations 3"):
251- # sa.delete_project(project)
252- # project = sa.create_project("test df to annotations 3", "test", "Vector")
253- # sa.upload_images_from_folder_to_project(project, PROJECT_DIR)
254- # sa.create_annotation_classes_from_classes_json(
255- # project, filtered_export / "classes" / "classes.json"
256- # )
257- # sa.upload_annotations_from_folder_to_project(project, filtered_export)
176+ def test_df_to_annotations (tmpdir ):
177+ tmpdir = Path (tmpdir )
178+
179+ df = sa .aggregate_annotations_as_df (PROJECT_DIR )
180+ sa .df_to_annotations (df , tmpdir )
181+ df_new = sa .aggregate_annotations_as_df (tmpdir )
182+
183+ assert len (df ) == len (df_new )
184+ # print(df_new["imageName"].value_counts())
185+ # print(df["imageName"].value_counts())
186+ # print(len(df.columns))
187+ # print(len(df_new.columns))
188+
189+ # print(df[df["imageName"] == "example_image_1.jpg"]["instanceId"])
190+ # print(df_new[(df_new["imageName"] == "example_image_1.jpg")]["instanceId"])
191+ for _index , row in enumerate (df .iterrows ()):
192+ for _ , row_2 in enumerate (df_new .iterrows ()):
193+ if row_2 [1 ].equals (row [1 ]):
194+ break
195+ # if row_2[1]["imageName"] == "example_image_1.jpg":
196+ # print(row_2[1])
197+ else :
198+ assert False , print ("Error on " , row [1 ])
199+
200+ for project in sa .search_projects ("test df to annotations 2" ):
201+ sa .delete_project (project )
202+ project = sa .create_project ("test df to annotations 2" , "test" , "Vector" )
203+ sa .upload_images_from_folder_to_project (
204+ project , "./tests/sample_project_vector"
205+ )
206+ sa .create_annotation_classes_from_classes_json (
207+ project , "./tests/sample_project_vector/classes/classes.json"
208+ )
209+ sa .upload_annotations_from_folder_to_project (
210+ project , "./tests/sample_project_vector"
211+ )
212+
213+
214+ def test_df_to_annotations_full (tmpdir ):
215+ tmpdir = Path (tmpdir )
216+
217+ df = sa .aggregate_annotations_as_df (
218+ PROJECT_DIR , include_classes_wo_annotations = True , include_comments = True
219+ )
220+ sa .df_to_annotations (df , tmpdir )
221+ df_new = sa .aggregate_annotations_as_df (
222+ tmpdir , include_classes_wo_annotations = True , include_comments = True
223+ )
224+ for project in sa .search_projects ("test df to annotations 4" ):
225+ sa .delete_project (project )
226+ project = sa .create_project ("test df to annotations 4" , "test" , "Vector" )
227+ sa .upload_images_from_folder_to_project (project , PROJECT_DIR )
228+ sa .create_annotation_classes_from_classes_json (
229+ project , tmpdir / "classes" / "classes.json"
230+ )
231+ sa .upload_annotations_from_folder_to_project (project , tmpdir )
232+ # print(df_new["image_name"].value_counts())
233+ # print(df["image_name"].value_counts())
234+ for _index , row in enumerate (df .iterrows ()):
235+ for _ , row_2 in enumerate (df_new .iterrows ()):
236+ if row_2 [1 ].equals (row [1 ]):
237+ break
238+ else :
239+ assert False
240+
241+ fil1 = sa .filter_annotation_instances (
242+ df_new ,
243+ include = [
244+ {
245+ "className" : "Personal vehicle" ,
246+ "attributes" : [{
247+ "name" : "4" ,
248+ "groupName" : "Num doors"
249+ }]
250+ }
251+ ],
252+ exclude = [{
253+ "type" : "polygon"
254+ }]
255+ )
256+ filtered_export = (tmpdir / "filtered" )
257+ filtered_export .mkdir ()
258+ sa .df_to_annotations (fil1 , filtered_export )
259+ for project in sa .search_projects ("test df to annotations 3" ):
260+ sa .delete_project (project )
261+ project = sa .create_project ("test df to annotations 3" , "test" , "Vector" )
262+ sa .upload_images_from_folder_to_project (project , PROJECT_DIR )
263+ sa .create_annotation_classes_from_classes_json (
264+ project , filtered_export / "classes" / "classes.json"
265+ )
266+ sa .upload_annotations_from_folder_to_project (project , filtered_export )
0 commit comments