def transcode(filename): tmpname = test_utils.temporary_filename(suffix=os.path.splitext(filename)[1]) tmpnam_ = test_utils.temporary_filename(suffix=os.path.splitext(filename)[1]) try: # complete transcoding test image = load(filename) # save with the same extension write(image, tmpname) # reload the image from the file image2 = load(tmpname) assert numpy.array_equal(image, image2) # test getting part of the image as well if len(image.shape) == 3: subsample = image[:,::2,::2] else: subsample = image[::2,::2] assert not subsample.flags.contiguous write(subsample, tmpnam_) image3 = load(tmpnam_) assert numpy.array_equal(subsample, image3) finally: if os.path.exists(tmpname): os.unlink(tmpname) if os.path.exists(tmpnam_): os.unlink(tmpnam_)
def transcode(filename): tmpname = test_utils.temporary_filename( suffix=os.path.splitext(filename)[1]) tmpnam_ = test_utils.temporary_filename( suffix=os.path.splitext(filename)[1]) try: # complete transcoding test image = load(filename) # save with the same extension write(image, tmpname) # reload the image from the file image2 = load(tmpname) assert numpy.array_equal(image, image2) # test getting part of the image as well if len(image.shape) == 3: subsample = image[:, ::2, ::2] else: subsample = image[::2, ::2] assert not subsample.flags.contiguous write(subsample, tmpnam_) image3 = load(tmpnam_) assert numpy.array_equal(subsample, image3) finally: if os.path.exists(tmpname): os.unlink(tmpname) if os.path.exists(tmpnam_): os.unlink(tmpnam_)
def test_persistence(): # make shure we can save an load an Machine machine weights = [] weights.append(numpy.array([[.2, -.1, .2], [.2, .3, .9]])) weights.append(numpy.array([[.1, .5], [-.1, .2], [-.1, 1.1]])) biases = [] biases.append(numpy.array([-.1, .3, .1])) biases.append(numpy.array([.2, -.1])) m = Machine((2,3,2)) m.weights = weights m.biases = biases # creates a file that will be used in the next test! machine_file = temporary_filename() m.save(bob.io.base.HDF5File(machine_file, 'w')) m2 = Machine(bob.io.base.HDF5File(machine_file)) assert m.is_similar_to(m2) nose.tools.eq_(m, m2) nose.tools.eq_(m.shape, m2.shape) assert (m.input_subtract == m2.input_subtract).all() assert (m.input_divide == m2.input_divide).all() for i in range(len(m.weights)): assert (m.weights[i] == m2.weights[i]).all() assert (m.biases[i] == m2.biases[i]).all()
def test_persistence(): # make shure we can save an load an Machine machine weights = [] weights.append(numpy.array([[.2, -.1, .2], [.2, .3, .9]])) weights.append(numpy.array([[.1, .5], [-.1, .2], [-.1, 1.1]])) biases = [] biases.append(numpy.array([-.1, .3, .1])) biases.append(numpy.array([.2, -.1])) m = Machine((2, 3, 2)) m.weights = weights m.biases = biases # creates a file that will be used in the next test! machine_file = temporary_filename() m.save(bob.io.base.HDF5File(machine_file, 'w')) m2 = Machine(bob.io.base.HDF5File(machine_file)) assert m.is_similar_to(m2) nose.tools.eq_(m, m2) nose.tools.eq_(m.shape, m2.shape) assert (m.input_subtract == m2.input_subtract).all() assert (m.input_divide == m2.input_divide).all() for i in range(len(m.weights)): assert (m.weights[i] == m2.weights[i]).all() assert (m.biases[i] == m2.biases[i]).all()
def test_io(): raise SkipTest("TODO: Not fully implemented yet") # Checks that the IO functionality of LBP works test_file = datafile("LBP.hdf5", __name__) temp_file = temporary_filename() # create file lbp1 = bob.ip.base.LBP(8, (2, 3), elbp_type="transitional", to_average=True, add_average_bit=True) lbp2 = bob.ip.base.LBP(16, 4., 2., uniform=True, rotation_invariant=True, circular=True) # re-generate the reference file, if wanted f = bob.io.base.HDF5File(temp_file, 'w') f.create_group("LBP1") f.create_group("LBP2") f.cd("/LBP1") lbp1.save(f) f.cd("/LBP2") lbp2.save(f) del f # load the file again f = bob.io.base.HDF5File(temp_file) f.cd("/LBP1") read1 = bob.ip.base.LBP(f) f.cd("/LBP2") read2 = bob.ip.base.LBP(f) del f # assert that the created and the read object are identical assert lbp1 == read1 assert lbp2 == read2 # load the reference file f = bob.io.base.HDF5File(test_file) f.cd("/LBP1") ref1 = bob.ip.base.LBP(f) f.cd("/LBP2") ref2 = bob.ip.base.LBP(f) del f # assert that the lbp objects and the reference ones are identical assert lbp1 == ref1 assert lbp2 == ref2 assert read1 == ref1 assert read2 == ref2
def test_io(): raise SkipTest("TODO: Not fully implemented yet") # Checks that the IO functionality of LBP works test_file = datafile("LBP.hdf5", __name__) temp_file = temporary_filename() # create file lbp1 = bob.ip.base.LBP(8, (2,3), elbp_type="transitional", to_average=True, add_average_bit=True) lbp2 = bob.ip.base.LBP(16, 4., 2., uniform=True, rotation_invariant=True, circular=True) # re-generate the reference file, if wanted f = bob.io.base.HDF5File(temp_file, 'w') f.create_group("LBP1") f.create_group("LBP2") f.cd("/LBP1") lbp1.save(f) f.cd("/LBP2") lbp2.save(f) del f # load the file again f = bob.io.base.HDF5File(temp_file) f.cd("/LBP1") read1 = bob.ip.base.LBP(f) f.cd("/LBP2") read2 = bob.ip.base.LBP(f) del f # assert that the created and the read object are identical assert lbp1 == read1 assert lbp2 == read2 # load the reference file f = bob.io.base.HDF5File(test_file) f.cd("/LBP1") ref1 = bob.ip.base.LBP(f) f.cd("/LBP2") ref2 = bob.ip.base.LBP(f) del f # assert that the lbp objects and the reference ones are identical assert lbp1 == ref1 assert lbp2 == ref2 assert read1 == ref1 assert read2 == ref2
def transcode(filename): tmpname = test_utils.temporary_filename(suffix=os.path.splitext(filename)[1]) try: # complete transcoding test image = load(filename) # save with the same extension write(image, tmpname) # reload the image from the file image2 = load(tmpname) assert numpy.array_equal(image, image2) finally: if os.path.exists(tmpname): os.unlink(tmpname)
def transcode(filename): tmpname = test_utils.temporary_filename( suffix=os.path.splitext(filename)[1]) try: # complete transcoding test image = load(filename) # save with the same extension write(image, tmpname) # reload the image from the file image2 = load(tmpname) assert numpy.array_equal(image, image2) finally: if os.path.exists(tmpname): os.unlink(tmpname)
def read_write(stem, fmt1, fmt2, encoding='UNKNOWN', bits_per_sample=16): f1 = reader(F(stem + fmt1)) data = f1.load() f2_filename = temporary_filename(suffix=fmt2) f2 = writer(f2_filename, rate=f1.rate, encoding=encoding, bits_per_sample=bits_per_sample) f2.append(data) f2.close() #forces file closing f2 = reader(f2_filename) nose.tools.eq_(f1.rate, f2.rate) data_f1 = f1.load() data_f2 = f2.load() # verify the data is the same assert numpy.array_equal(data_f1, data_f2), '%r != %r' % (data_f1, data_f2)