MCPcopy Create free account
hub / github.com/BMEII-AI/RadImageNet / get_compiled_model

Function get_compiled_model

pneumonia/pneumonia_train.py:126–168  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124
125### Creat model
126def get_compiled_model():
127 if not args.model_name in ['IRV2', 'ResNet50', 'DenseNet121', 'InceptionV3']:
128 raise Exception('Pre-trained network not exists. Please choose IRV2/ResNet50/DenseNet121/InceptionV3 instead')
129 else:
130 if args.model_name == 'IRV2':
131 if database == 'RadImageNet':
132 model_dir ="../RadImageNet_models/RadImageNet-IRV2-notop.h5"
133 base_model = InceptionResNetV2(weights=model_dir, input_shape=(image_size, image_size, 3), include_top=False,pooling='avg')
134 else:
135 base_model = InceptionResNetV2(weights='imagenet', input_shape=(image_size, image_size, 3),include_top=False,pooling='avg')
136 if args.model_name == 'ResNet50':
137 if database == 'RadImageNet':
138 model_dir = "../RadImageNet_models/RadImageNet-ResNet50-notop.h5"
139 base_model = ResNet50(weights=model_dir, input_shape=(image_size, image_size, 3), include_top=False,pooling='avg')
140 else:
141 base_model = ResNet50(weights='imagenet', input_shape=(image_size, image_size, 3), include_top=False,pooling='avg')
142 if args.model_name == 'DenseNet121':
143 if database == 'RadImageNet':
144 model_dir = "../RadImageNet_models/RadImageNet-DenseNet121-notop.h5"
145 base_model = DenseNet121(weights=model_dir, input_shape=(image_size, image_size, 3), include_top=False,pooling='avg')
146 else:
147 base_model = DenseNet121(weights='imagenet', input_shape=(image_size, image_size, 3), include_top=False,pooling='avg')
148 if args.model_name == 'InceptionV3':
149 if database == 'RadImageNet':
150 model_dir = "../RadImageNet_models/RadImageNet-InceptionV3-notop.h5"
151 base_model = InceptionV3(weights=model_dir, input_shape=(image_size, image_size, 3), include_top=False,pooling='avg')
152 else:
153 base_model = InceptionV3(weights='imagenet', input_shape=(image_size, image_size, 3), include_top=False,pooling='avg')
154 if args.structure == 'freezeall':
155 for layer in base_model.layers:
156 layer.trainable = False
157 if args.structure == 'unfreezeall':
158 pass
159 if args.structure == 'unfreezetop10':
160 for layer in base_model.layers[:-10]:
161 layer.trainable = False
162 y = base_model.output
163 y = Dropout(0.5)(y)
164 predictions = Dense(num_classes, activation='softmax')(y)
165 model = Model(inputs=base_model.input, outputs=predictions)
166 adam = Adam(lr=args.lr)
167 model.compile(optimizer=adam, loss=BinaryCrossentropy(), metrics=['acc'])
168 return model
169
170
171

Callers 1

pneumonia_train.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected