How to use get_base_model method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

model.py

Source:model.py Github

copy

Full Screen

2from abc import ABC, abstractmethod3class ImageBaseModel(ABC):4 @classmethod5 @abstractmethod6 def get_base_model(cls, h:int,w:int,c:int):7 """ベースとなるモデルを提供する。8 9 Args:10 ImageBaseModel ([type]): [description]11 h (int): 入力サイズ hight12 w (int): 入力サイズ width13 c (int): 入力サイズ channel14 15 Returns:16 [type]: CNNモデル17 """18 raise NotImplementedError()19class ClasificationModel(ABC):20 @classmethod21 @abstractmethod22 def get_classification_model(cls, base_model:tf.keras.Model)->tf.keras.Model:23 """ ベースモデルに分類部分をつけた分類用のモデルを提供する。24 25 Args:26 base_model (tf.keras.Model): ベースモデル27 classes (int): 分類数28 29 Returns:30 tf.keras.Model: 分類モデル31 """32 raise NotImplementedError()33class SimpleCNN(ImageBaseModel):34 @classmethod35 def get_base_model(cls, h:int,w:int,c:int):36 """単純なCNNモデルを提供する。37 38 Args:39 ImageBaseModel ([type]): [description]40 h (int): 入力サイズ hight41 w (int): 入力サイズ width42 c (int): 入力サイズ channel43 44 Returns:45 [type]: CNNモデル46 """47 input_layer = tf.keras.Input(shape=(h,w,c),name='input',dtype=tf.float32)48 x = tf.keras.layers.Conv2D(32, (3, 3), padding='same', name='conv2d-1')(input_layer)49 x = tf.keras.layers.Activation('relu')(x)50 x = tf.keras.layers.Conv2D(32, (3, 3), padding='same', name='conv2d-2')(x)51 x = tf.keras.layers.Activation('relu')(x)52 x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2),name='maxpool-1')(x)53 x = tf.keras.layers.Dropout(0.25)(x)54 x = tf.keras.layers.Conv2D(32, (3, 3), padding='same', name='conv2d-3')(x)55 x = tf.keras.layers.Activation('relu')(x)56 x = tf.keras.layers.Conv2D(32, (3, 3), padding='same', name='conv2d-4')(x)57 x = tf.keras.layers.Activation('relu')(x)58 x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2),name='maxpool-2')(x)59 return tf.keras.Model(input_layer,x)60class ResNet50(ImageBaseModel):61 @classmethod62 def get_base_model(cls, h:int,w:int,c:int, weights:bool=False):63 """ResNet CNNモデルを提供する。64 65 Args:66 ImageBaseModel ([type]): [description]67 h (int): 入力サイズ hight68 w (int): 入力サイズ width69 c (int): 入力サイズ channel70 71 Returns:72 [type]: CNNモデル73 """74 if weights==False:75 w_imagenet = None76 else:77 w_imagenet = "imagenet"78 model = tf.keras.applications.ResNet50(include_top=False,input_shape=(h,w,c),weights=w_imagenet)79 return model80class SimpleSoftmaxClassificationModel(ClasificationModel):81 @classmethod82 def get_classification_model(cls, base_model:tf.keras.Model,classes:int)->tf.keras.Model:83 """ ベースモデルに分類部分をつけた分類用のモデルを提供する。84 85 Args:86 base_model (tf.keras.Model): ベースモデル87 classes (int): 分類数88 89 Returns:90 tf.keras.Model: 分類モデル91 """92 x = tf.keras.layers.Flatten()(base_model.output)93 x = tf.keras.layers.Activation('relu')(x)94 x = tf.keras.layers.Dense(100)(x)95 x = tf.keras.layers.Activation('relu')(x)96 x = tf.keras.layers.Dense(classes, activation='softmax')(x)97 return tf.keras.Model(base_model.input, x)98if __name__ == '__main__':99 base = SimpleCNN.get_base_model(28,28,1)100 model = SimpleSoftmaxClassificationModel.get_classification_model(base,10)...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...51 model.fit(x=x, y=y, epochs=5, batch_size=4, validation_split=0.1, verbose=0)52 def test_model_dsc(self):53 x = np.array([[5, 2, 3] * 3] * 100)54 y = np.array([[1, 2, 3] * 3] * 100)55 base_model = get_base_model(9)56 model = ModelWithCRFLossDSCLoss(base_model)57 model.compile(optimizer='adam')58 model.fit(x=x, y=y, epochs=5, batch_size=4, validation_split=0.1, verbose=0)59 def test_mixed_precison_dsc(self):60 from tensorflow.keras.mixed_precision import experimental as mixed_precision61 x = np.array([[5, 2, 3] * 3] * 100)62 y = np.array([[1, 2, 3] * 3] * 100)63 policy = mixed_precision.Policy('mixed_float16')64 mixed_precision.set_policy(policy)65 base_model = get_base_model(9)66 model = ModelWithCRFLossDSCLoss(base_model)67 model.compile(optimizer='adam')68 model.fit(x=x, y=y, epochs=5, batch_size=4, validation_split=0.1, verbose=0)69def get_model(units: int):70 base_model = get_base_model(units)71 model = ModelWithCRFLoss(base_model)72 model.compile(optimizer='adam')73 return model74def get_base_model(units: int):75 inputs = Input(shape=(None,), dtype='int32')76 output = Embedding(10, 20, trainable=True, mask_zero=True)(inputs)77 crf = CRF(units=units, dtype='float32', name='crf')78 output = crf(output)79 base_model = Model(inputs=inputs, outputs=output)80 return base_model81if __name__ == "__main__":...

Full Screen

Full Screen

test_base_model.py

Source:test_base_model.py Github

copy

Full Screen

1import pytest2from model.base_model import BaseModel3def get_base_model(problem):4 return BaseModel("test", problem)5@pytest.mark.parametrize("problem_name, expected", [("rproblem2", [0]), ("rproblem3", [0])])6def test_model_competencies(problem_name, expected):7 base_model = get_base_model(problem_name)8 assert base_model.competencies == expected9@pytest.mark.parametrize(10 "problem_name, expected_length, expected_start",11 [("rproblem2", 1170, [8.0, 8.5, 9, 9.5]), ("rproblem3", 1176, [7.75, 8.0, 8.25, 8.5])],12)13def test_model_time_periods(problem_name, expected_length, expected_start):14 base_model = get_base_model(problem_name)15 time_periods = base_model.time_set["periods"][0]16 assert len(time_periods) == expected_length17 assert time_periods[:4] == expected_start18@pytest.mark.parametrize(19 "problem_name, expected_length, expected_start",20 [("rproblem2", 10, [8.0, 8.5, 9, 9.5]), ("rproblem3", 4, [7.75, 8.0, 8.25, 8.5])],21)22def test_model_time_periods_in_week(problem_name, expected_length, expected_start):23 base_model = get_base_model(problem_name)24 time_periods = base_model.time_set["periods"][1]25 assert len(time_periods) == expected_length26 assert time_periods[0][:4] == expected_start27def test_get_variables_returns_none():28 """ The base model should not contain any variables """29 base_model = get_base_model("problem12")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful