export_confusion_files = False

train_type = 'wide_angle'
data_version = 'v5'
csv_file = Path(__file__).parent.parent.absolute().joinpath(
    'datafiles', data_version, 'test.csv')

num_classes = 4
thresholds = [0.5 for x in range(num_classes)]

dicts_models = []

model_name = 'xception'
model_file = '/tmp2/wide_angel/v3/xception/epoch7.pth'
model, input_shape = load_model(model_name,
                                num_class=num_classes,
                                model_file=model_file,
                                get_image_shape=True)
dict_model1 = {
    'model': model,
    'input_shape': input_shape,
    'model_weight': 1,
    'batch_size': 64
}
dicts_models.append(dict_model1)

model_name = 'inception_v3'
model_file = '/tmp2/wide_angel/v3/inception_v3/epoch8.pth'
model, input_shape = load_model(model_name,
                                num_class=num_classes,
                                model_file=model_file,
                                get_image_shape=True)
Пример #2
0
from torch.utils.data import DataLoader
from libs.dataset.my_dataset import Dataset_CSV
from libs.neural_networks.heatmaps.t_SNE.my_tsne_helper import compute_features_files, gen_tse_features, draw_tsne

num_classes = 4
csv_file = os.path.join(os.path.abspath('../..'), 'datafiles', 'v5',
                        'test.csv')
save_features = False

model_name = 'inception_v3'

#region load model
if model_name == 'xception':
    model_file = '/tmp2/wide_angel/v3/xception/epoch7.pth'
    model, image_shape = load_model(model_name,
                                    num_class=num_classes,
                                    model_file=model_file)
    layer_features = model.global_pool
    batch_size = 32

if model_name == 'inception_v3':
    model_file = '/tmp2/wide_angel/v3/inception_v3/epoch8.pth'
    model, image_shape = load_model(model_name,
                                    num_class=num_classes,
                                    model_file=model_file)
    layer_features = model.global_pool
    batch_size = 32

if model_name == 'inception_resnet_v2':
    model_file = '/tmp2/wide_angel/v3/inception_resnet_v2/epoch8.pth'
    model, image_shape = load_model(model_name,
sample_weights = []
for label in df['labels']:
    sample_weights.append(sample_class_weights[label])
sampler = WeightedRandomSampler(weights=sample_weights, num_samples=len(df))
'''

# endregion

# region training
# 'tf_efficientnet_b0', 'res2net50_26w_4s', 'resnet50d' , 'resnest50d'
# 'xception', 'inception_resnet_v2', 'inception_v3'
# for model_name in ['resnest50d', 'resnest101e', 'res2net50_26w_6s', 'tf_efficientnet_b2', 'tf_efficientnet_b3', 'xception', 'inception_resnet_v2', 'inception_v3']:
# for model_name in ['tf_efficientnet_b2', 'tf_efficientnet_b3', 'xception', 'inception_v3', 'inception_resnet_v2', 'resnest50d_4s2x40d', 'resnest101e', 'res2net50_26w_6s']:
for model_name in ['inception_resnet_v2', 'xception', 'inception_v3']:
    model, image_shape = load_model(model_name,
                                    num_class=num_class,
                                    get_image_shape=True)

    loss_pos_weights = torch.FloatTensor(positive_weights)
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    if torch.cuda.device_count() > 0:
        model.to(device)
        loss_pos_weights = loss_pos_weights.cuda()

    ds_train = Dataset_CSV(data_source=csv_train,
                           imgaug_iaa=iaa,
                           image_shape=image_shape)
    loader_train = DataLoader(ds_train,
                              batch_size=batch_size_train,
                              shuffle=True,
                              num_workers=num_workers)
Пример #4
0
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ""
import torch
from libs.neural_networks.models.my_load_model import load_model

num_classes = 4

model_name = 'xception'
model_file = '/tmp2/wide_angel/v3/xception/epoch7.pth'
model = load_model(model_name,
                   num_class=num_classes,
                   model_file=model_file,
                   get_image_shape=False)
'''
model_name = 'inception_v3'
model_file = '/tmp2/wide_angel/v3/inception_v3/epoch8.pth'
model = load_model(model_name, num_class=num_classes, model_file=model_file, get_image_shape=False)

model_name = 'inception_resnet_v2'
model_file = '/tmp2/wide_angel/v3/inception_resnet_v2/epoch8.pth'
model = load_model(model_name, num_class=num_classes, model_file=model_file, get_image_shape=False)
'''

scripted_module = torch.jit.script(model)

# model.eval()
#import numpy as np
# inputs_test = torch.from_numpy(np.zeros((1, 3, 299, 299), dtype=float))
# store = torch.jit.trace(model, inputs_test)