def test_from_data_frame(self): dframe1 = DictFrame({"x": [0, 1, 2], "y": ["a", "b", "c"]}) pdf = dframe1.todf() dframe2 = pd_to_dict_frame(pdf) assert set(pdf.columns) == set(["x", "y"]) assert dframe1 == dframe2
def test_to_data_frame(self): dframe = DictFrame({ "x": [0, 1, 2], "y": ["a", "b", "c"], "embed": np.random.normal(0, 1, (3, 20)), }) exp_cols = ["x", "y"] + ["embed-{0:d}".format(x) for x in range(20)] pdf = dframe.todf() assert set(pdf.columns) == set(exp_cols) assert issubclass(type(pdf), pd.core.frame.DataFrame)
def test_process_empty_output(self): fpobj = FrameProcessor() fpobj.load_annotator(FrameAnnotator()) finput = FrameInput("test-data/video-clip.mp4", bsize=4) fpobj.process(finput) assert fpobj.collect("base") == DictFrame()
def test_add(self): dframe1 = DictFrame({ "x": [0, 1, 2], "y": ["a", "b", "c"], "embed": np.random.normal(0, 1, (3, 20)), }) dframe2 = DictFrame({ "x": [0, 1], "y": ["a", "b"], "embed": np.random.normal(0, 1, (2, 20)), }) dframe3 = dframe1 + dframe2 assert set(dframe3.keys()) == set(["x", "y", "embed"]) assert issubclass(type(dframe3["embed"]), np.ndarray) assert dframe3.shape == (5, 3)
def test_collect_all(self): fpobj = FrameProcessor() fpobj.load_annotator(FrameAnnotator()) fpobj.load_annotator(DiffAnnotator()) finput = FrameInput("test-data/video-clip.mp4", bsize=8) fpobj.process(finput, max_batch=2) output = fpobj.collect_all() assert output["base"] == DictFrame() assert output["diff"].shape[0] == (2 * 8)
def test_png_resize(self): dname = tempfile.mkdtemp() # creates directory fpobj = FrameProcessor() fpobj.load_annotator(PngAnnotator(output_dir=dname, size=(32, 64))) finput = FrameInput("test-data/video-clip.mp4", bsize=4) fpobj.process(finput, max_batch=2) expected_files = set(["frame-{0:06d}.png".format(x) for x in range(8)]) obj_out = fpobj.collect("png") assert obj_out == DictFrame() assert set(os.listdir(dname)) == expected_files
def test_cutoff_ignore(self): fpobj = FrameProcessor() fpobj.load_annotator(DiffAnnotator(quantiles=[40])) finput = FrameInput("test-data/video-clip.mp4", bsize=128) fpobj.process(finput, max_batch=2) obj_out = fpobj.collect_all() ca = CutAggregator( cut_vals={"h40": 0.2, "q40": 3}, ignore_vals={"avg_value": 70} ) agg = ca.aggregate(obj_out) assert agg == DictFrame()
def test_channels(self): finput = FrameInput("test-data/video-clip.mp4", bsize=1) batch = get_batch(finput, batch_num=0) img = batch.get_frames()[0, :, :, :] face = DictFrame({"top": 0, "bottom": 96, "left": 0, "right": 96}) femb = FaceEmbedVgg2() femb._iformat = "channels_first" emb1 = femb.embed(img, face) femb._iformat = "channels_last" emb2 = femb.embed(img, face) assert (emb1 != emb2).any()
def test_bad_length(self): # check assertion on input with pytest.raises(AssertionError): dframe = DictFrame({"x": [0, 1], "y": ["a", "b", "c"]}) # check assertion after the fact dframe = DictFrame({"x": [0, 1], "y": ["a", "b", "c"]}, check=False) with pytest.raises(AssertionError): dframe.verify()
def test_png_image(self): dname = tempfile.mkdtemp() # creates directory fpobj = FrameProcessor() fpobj.load_annotator(PngAnnotator(output_dir=dname)) iobj = ImageInput(input_paths=[ "test-data/img/frame-000076.png", "test-data/img/frame-000506.png", ]) fpobj.process(iobj, max_batch=2) # assert that all of the images in the input exist in output expected_files = set(["frame-000076.png", "frame-000506.png"]) obj_out = fpobj.collect("png") assert obj_out == DictFrame() assert set(os.listdir(dname)) == expected_files # make sure images are the same img1 = cv2.imread(os.path.join("test-data/img/frame-000076.png")) img2 = cv2.imread(os.path.join(dname, "frame-000076.png")) assert np.all(img1 == img2)
def test_scalar_input(self): dframe = DictFrame({"x": 0, "y": ["a"]}) assert dframe["x"] == [0] assert dframe["y"] == ["a"]
def test_empty_dict(self): empty = DictFrame() assert empty.shape == (0, 0)