Python maskrcnn_benchmark.utils.checkpoint.Checkpointer() Examples
The following are 28
code examples of maskrcnn_benchmark.utils.checkpoint.Checkpointer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maskrcnn_benchmark.utils.checkpoint
, or try the search function
.
Example #1
Source File: checkpoint.py From FreeAnchor with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #2
Source File: checkpoint.py From maskscoring_rcnn with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #3
Source File: checkpoint.py From maskscoring_rcnn with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #4
Source File: checkpoint.py From DF-Traffic-Sign-Identification with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #5
Source File: checkpoint.py From DF-Traffic-Sign-Identification with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #6
Source File: checkpoint.py From RRPN_pytorch with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #7
Source File: checkpoint.py From RRPN_pytorch with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #8
Source File: checkpoint.py From NAS-FCOS with BSD 2-Clause "Simplified" License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #9
Source File: checkpoint.py From NAS-FCOS with BSD 2-Clause "Simplified" License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #10
Source File: checkpoint.py From training with Apache License 2.0 | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #11
Source File: checkpoint.py From training with Apache License 2.0 | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #12
Source File: checkpoint.py From retinamask with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #13
Source File: checkpoint.py From retinamask with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #14
Source File: checkpoint.py From FreeAnchor with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #15
Source File: checkpoint.py From Res2Net-maskrcnn with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #16
Source File: checkpoint.py From maskrcnn-benchmark with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #17
Source File: checkpoint.py From maskrcnn-benchmark with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #18
Source File: checkpoint.py From HRNet-MaskRCNN-Benchmark with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #19
Source File: checkpoint.py From HRNet-MaskRCNN-Benchmark with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #20
Source File: checkpoint.py From sampling-free with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #21
Source File: checkpoint.py From sampling-free with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #22
Source File: checkpoint.py From remote_sensing_object_detection_2019 with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #23
Source File: checkpoint.py From remote_sensing_object_detection_2019 with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #24
Source File: checkpoint.py From DetNAS with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #25
Source File: checkpoint.py From DetNAS with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #26
Source File: checkpoint.py From R2CNN.pytorch with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #27
Source File: checkpoint.py From R2CNN.pytorch with MIT License | 5 votes |
def test_from_last_checkpoint_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # in the same folder fresh_checkpointer = Checkpointer(fresh_model, save_dir=f) self.assertTrue(fresh_checkpointer.has_checkpoint()) self.assertEqual( fresh_checkpointer.get_checkpoint_file(), os.path.join(f, "checkpoint_file.pth"), ) _ = fresh_checkpointer.load() for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))
Example #28
Source File: checkpoint.py From Res2Net-maskrcnn with MIT License | 5 votes |
def test_from_name_file_model(self): # test that loading works even if they differ by a prefix for trained_model, fresh_model in [ (self.create_model(), self.create_model()), (nn.DataParallel(self.create_model()), self.create_model()), (self.create_model(), nn.DataParallel(self.create_model())), ( nn.DataParallel(self.create_model()), nn.DataParallel(self.create_model()), ), ]: with TemporaryDirectory() as f: checkpointer = Checkpointer( trained_model, save_dir=f, save_to_disk=True ) checkpointer.save("checkpoint_file") # on different folders with TemporaryDirectory() as g: fresh_checkpointer = Checkpointer(fresh_model, save_dir=g) self.assertFalse(fresh_checkpointer.has_checkpoint()) self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "") _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth")) for trained_p, loaded_p in zip( trained_model.parameters(), fresh_model.parameters() ): # different tensor references self.assertFalse(id(trained_p) == id(loaded_p)) # same content self.assertTrue(trained_p.equal(loaded_p))