-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added model source parameter; fixes #56
- Loading branch information
1 parent
32236ee
commit 1c174f4
Showing
3 changed files
with
169 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import unittest | ||
|
||
import tests.helper as helper | ||
|
||
import numpy as np | ||
import tensorflow as tf | ||
from torchvision import transforms as T | ||
from thingsvision.model_class import Model | ||
|
||
class ModelLoadingTestCase(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
helper.create_test_images() | ||
|
||
def test_mode_and_device(self): | ||
model_name = 'vgg16_bn' | ||
model, dataset, dl = helper.create_model_and_dl(model_name, 'pt') | ||
self.assertTrue(hasattr(model.model, helper.DEVICE)) | ||
self.assertFalse(model.model.training) | ||
|
||
def test_load_model_without_source(self): | ||
model_name = 'vgg16' | ||
model = Model(model_name, False, 'cpu') | ||
self.assertEqual(model.model.__class__.__name__, 'VGG') | ||
|
||
with self.assertRaises(): | ||
model_name = 'random_model' | ||
model = Model(model_name, False, 'cpu') | ||
|
||
def test_load_custom_user_model(self): | ||
model_name = 'VGG16bn_ecoset' | ||
model = Model(model_name, False, 'cpu') | ||
self.assertEqual(model.model.__class__.__name__, 'VGG', source='custom') | ||
|
||
model_name = 'Resnet50_ecoset' | ||
model = Model(model_name, False, 'cpu') | ||
self.assertEqual(model.model.__class__.__name__, 'ResNet', source='custom') | ||
|
||
model_name = 'Alexnet_ecoset' | ||
model = Model(model_name, False, 'cpu') | ||
print(model.__class__.__name__) | ||
self.assertEqual(model.model.__class__.__name__, 'AlexNet', source='custom') | ||
|
||
with self.assertRaises(): | ||
model_name = 'random_model' | ||
model = Model(model_name, False, 'cpu', source='custom') | ||
|
||
def test_load_timm_models(self): | ||
model_name = 'mixnet_l' | ||
model = Model(model_name, False, 'cpu') | ||
self.assertEqual(model.model.__class__.__name__, 'EfficientNet', source='timm') | ||
|
||
with self.assertRaises(): | ||
model_name = 'random_model' | ||
model = Model(model_name, False, 'cpu', source='timm') | ||
|
||
def test_load_torchvision_models(self): | ||
model_name = 'vgg16' | ||
model = Model(model_name, False, 'cpu') | ||
self.assertEqual(model.model.__class__.__name__, 'VGG', source='torchvision') | ||
|
||
with self.assertRaises(): | ||
model_name = 'random_model' | ||
model = Model(model_name, False, 'cpu', source='torchvision') | ||
|
||
def test_load_keras_models(self): | ||
model_name = 'VGG16' | ||
model = Model(model_name, False, 'cpu') | ||
self.assertEqual(model.model.__class__.__name__, 'VGG', source='keras') | ||
|
||
with self.assertRaises(): | ||
model_name = 'random_model' | ||
model = Model(model_name, False, 'cpu', source='keras') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters