Beispiel #1
0
 def testName(self):
     
     # read data
     data = reader.read("../data/log_1_fixed.txt", jstartline=15000, maxlines=5000)
             
     # preprocess data
     preprocess.preproc(data)
     
     # initialize model
     layers = [13, 8, 1]
     activf = [activation.linear(), activation.tanh(), activation.sigmoid()] #  ,  activation.tanh(1.75, 3./2.),
     net = ffnet.FFNet(layers, activf)
     net.initw(0.1) 
     
     # create training options
     opts = trainb.options()
     
     # write function
     f = open("../output/trainb_test.txt", "w+")
     writefcn = lambda s: f.write(s)
             
     # training
     trainb.train(data, opts, net, writefcn)
     
     # close file
     f.close()
Beispiel #2
0
    def testName(self):

        # read data
        data = reader.read("../data/log_1_fixed.txt",
                           jstartline=15000,
                           maxlines=5000)

        # preprocess data
        preprocess.preproc(data)

        # initialize model
        layers = [13, 8, 1]
        activf = [
            activation.linear(),
            activation.tanh(),
            activation.sigmoid()
        ]  # activation.tanh(1.75, 3./2.),
        net = ffnet.FFNet(layers, activf)
        net.initw(0.1)

        # create training options
        opts = trainsg.options()

        # write function
        f = open("../output/trainsg_test.txt", "w+")
        writefcn = lambda s: f.write(s)

        # training
        trainsg.train(data, opts, net, writefcn)

        # close file
        f.close()
Beispiel #3
0
def run(_):
    if config.mode == "train":
        train(config, device)
    elif config.mode == "preprocess":
        preproc(config)

    elif config.mode == "debug":
        config.epochs = 1
        config.batch_size = 3
        config.val_batch_size = 20
        config.checkpoint = 1
        config.period = 1
        train(config, device)
    elif config.mode == "test":
        pass
    elif config.mode == "dev":
        dev(config, device)
    else:
        print("Unknown mode")
        exit(0)
Beispiel #4
0
def main():

    # load training data
    data = reader.read("../data/log_1_fixed.txt")

    # preprocess
    preprocess.preproc(data)

    # shuffle data
    perm = range(len(data))
    random.shuffle(perm)

    # train a network
    ntrain = 100000
    dtrain = la.idxview(data, perm[:ntrain])

    net = train(0, dtrain)

    # evaluate on training data
    evaluate(dtrain, net)

    # evaluate on test data
    devaluate = la.idxview(data, perm[ntrain:2 * ntrain])
    evaluate(devaluate, net)
Beispiel #5
0
def main():

    # load training data
    data = reader.read("../data/log_1_fixed.txt")
    
    # preprocess 
    preprocess.preproc(data)
    
    # shuffle data
    perm = range(len(data))
    random.shuffle(perm)
    
    # train a network
    ntrain = 100000
    dtrain = la.idxview(data, perm[:ntrain])
    
    net = train(0, dtrain)
    
    # evaluate on training data
    evaluate(dtrain, net)
        
    # evaluate on test data
    devaluate = la.idxview(data, perm[ntrain:2*ntrain])
    evaluate(devaluate, net)
Beispiel #6
0
                    epochs=EPOCHS,
                    steps_per_epoch=dtgen.steps['train'],
                    validation_data=dtgen.next_valid_batch(),
                    validation_steps=dtgen.steps['valid'],
                    callbacks=callbacks,
                    shuffle=True,
                    verbose=1
                    )

model.save(f"saved_model/Flor/{INPUT_SOURCE_NAME}_filter")


# Predict
PREDICT_IMAGE_SRC = "hello.png"
tokenizer = Tokenizer(chars=CHARSET_BASE, max_text_length=MAX_TEXT_LENGTH)
img = preproc(PREDICT_IMAGE_SRC, input_size=INPUT_SHAPE)
x_test = normalization([img])

STEPS = 1

out = model.predict(
    x=x_test,
    batch_size=None,
    verbose=False,
    steps=STEPS,
    callbacks=None,
    max_queue_size=10,
    workers=1,
    use_multiprocessing=False
)
from balance_dataloader import BalancedBatchSampler
from densenet import densenet121, densenet201, densenet161
from preprocess import preproc
from ArcMarginModel import ArcMarginModel_AutoMargin
from FocalLoss import FocalLoss
import timm

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'


training_csv = './main/train.csv'
validate_csv = './main/val.csv'
data = './data/ISIC2018_Task3_Training_Input'
labels_names = ['MEL', 'NV', 'BCC', 'AKIEC', 'BKL', 'DF', 'VASC']

training = dataloader(training_csv, data, preproc(), 'training')
validation = dataloader(validate_csv, data, preproc(), 'validate')

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

dataloaders = {'train': training, 'val': validation}


def visualizing(phase, epoch, step, epoch_loss, epoch_acc):
    # training visualizing
    if epoch == 0 and step == 0:
        writer.add_scalar(f'{phase} loss', epoch_loss, 0)
        writer.add_scalar(f'{phase} accuracy', 0, 0)
    ######################
    else:
        writer.add_scalar(f'{phase} loss',
Beispiel #8
0
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# import cadastro_usuarios as cadastro
import preprocess as pp

#diretorio2='/home/caroline/Documentos/iotprogram
diretorio2 = 'iotprograms'
### xxxxxxxxxxxxxxxxxx ESTAGIO DE RECONHECIMENTO xxxxxxxxxxxxxxxxxx ###

# Imagem Teste

path_teste = diretorio2 + '/fotosteste/Teste.pgm'

face_teste = cv2.imread(path_teste, 0)
ImgTeste = pp.preproc(face_teste)

cv2.imshow('img', ImgTeste)
cv2.waitKey(0)
cv2.destroyAllWindows()

print('\n\n')

size_rows = 92
size_cols = 80
size_img = size_rows * size_cols

ImgRe = np.zeros((size_img, 1))
ImgIm = np.zeros((size_img, 1))
ImgDFT = np.zeros((size_img, 1, 2))
# ImgDFT = np.zeros((size_rows, size_cols, 2))
Beispiel #9
0
			if novo_indice.all() == 0:
				print 'Theta < 10 para todas as fotos.'
				k = False
			else:
				minimo_indice = novo_indice[minimo_indice]
				indice = novo_indice
				loop = 0
			print(novo_indice)
			print('---------------')
		if k==True:
			if loop == 0 and minimo_indice!=0:
				# V e o vetor referencia para calculo do cosseno
				pathV = '/home/caroline/Documentos/Smart_room/BancoDeDados/Treinamento/'+str(name)+'/'+nome_img+str(minimo_indice)+'p.pgm'
				V = cv2.imread(pathV, cv2.CV_LOAD_IMAGE_GRAYSCALE)
				print(pathV)
				imgV = pp.preproc(V)

				rows,cols = imgV.shape
				tripaU = np.zeros((rows*cols,1))
				tripaV = np.zeros((rows*cols,1))
				novo_indice = np.array([0])

				ind = j = i = 0
				while j<cols:
					while i<rows:
						tripaV[ind][0] = imgV[i][j]
						i = i +1
						ind = ind +1
					j = j +1

			elif indice[loop-1]!=0:
Beispiel #10
0
    matX = np.zeros((size_img, total_img, 2))
    matXtr = np.zeros((total_img, size_img, 2))
    matReX = np.zeros((size_img, total_img))
    matImX = np.zeros((size_img, total_img))
    matXpow = np.zeros((size_img, total_img))
    vetD = np.zeros((size_img, 1))
    matY = np.zeros((size_img, total_img, 2))
    H = np.zeros((1, size_img, 2))

    while num_img < total_img:

        path = '/home/caroline/Documentos/Smart_room/BancoDeDados/Filtros/' + name + '/foto_' + str(
            num_img + 1) + '.pgm'
        face = cv2.imread(path, cv2.CV_LOAD_IMAGE_GRAYSCALE)
        img = pp.preproc(face)  # 1.3 > img > -1.0

        # cv2.imshow('img', img)
        # cv2.waitKey(0)
        # cv2.destroyAllWindows()

        rows = 0

        # 2D image --->>>  1D image
        for j in xrange(0, size_cols):
            for i in xrange(0, size_rows):
                matRe[rows] = img[i, j]
                rows = rows + 1

        # matRe = matRe - avg(matRe)
        matReAvg = cv2.mean(matRe)
Beispiel #11
0
from dataset import dataloader
from preprocess import preproc
import pickle

warnings.filterwarnings("ignore", category=SourceChangeWarning)

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

# data and model paths
test_data = '../../data/ISIC2018_Task3_Training_Input'
model_path = './weights/densenet121_ArcMargin_2021-01-22_1-12_epoch99.tar'

labels_names = ['MEL', 'NV', 'BCC', 'AKIEC', 'BKL', 'DF', 'VASC']

# dataloader
test_loader = dataloader(None, test_data, preproc(), 'test')

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")


def full_crop(image):
    img_t = []
    for r in range(0, 4):
        for c in range(0, 5):
            img_t.append(image[:, 50*r:50*r+300, 50*c:50*c+400])
    return img_t


def summision_generate(model, batch_size, arccos=None, voting=True):

    result = {}
Beispiel #12
0
        if len(qntfaces) == 1:
            #desenhando retangulo ao redor de cada face:

            for (x, y, w, h) in qntfaces:

                cv2.rectangle(image, (x, y), (x + w, y + h), (255, 255, 0), 2)

                face = image[y:y + w,
                             x:x + h]  #recortando  imagem atraves do retangulo
                face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)

                # Se nesse momento quisesse salvar seria assim mas n quero salvar
                # path_face = '/home/pi/Documents/iotprograms/preproc/'+ str(nome) +'/'+str(num_foto) +'.pgm'
                # cv2.imwrite(path_face,face) #salvando a imagem

            facepp = pp.preproc(face)

            cv2.imshow('face pre process', facepp)
            cv2.waitKey(0)
            cv2.destroyAllWindows()

            path_facepp = '/home/pi/Documents/iotprograms/preproc/' + str(
                nome) + '/' + str(num_foto) + '.pgm'
            cv2.imwrite(path_facepp, facepp)

    num_foto = num_foto + 1

############## --------- PROGRAMA 2 ------------------- INICIO -------------------------------------###########################################
# Para usar o programa 2 comente o programa 1 e descomente o programada 2

# total_fotos = 3
Beispiel #13
0
NomeImgRef = AllNames[IndThetaMin]
NomeImg = AllNames[Ind]

NewAllNames = AllNames

Menor10 = False

while AllNames[IndThetaMin] != AllNames[Ind]:


	# Imagem Referencia -------------------------------------------------------------------------------------------------------

	PathImgRef = Path +NomeImgRef

	ImgRef = cv2.imread(PathImgRef,0)
	ImgRef = pp.preproc(ImgRef)

	print(('\n\nImagem Referencia: {} '.format(NomeImgRef)))


	# 2a Imagem ---------------------------------------------------------------------------------------------------------------

	PathImg = Path +NomeImg

	Img = cv2.imread(PathImg,0)
	Img = pp.preproc(Img)


	print(('2a Imagem : {} '.format(NomeImg)))

	# 2D ->>>>> 1D ------------------------------------------------------------------------------------------------------------
Beispiel #14
0
    if len(qntfaces) == 1:
        #desenhando retangulo ao redor de cada face:

        for (x, y, w, h) in qntfaces:

            cv2.rectangle(image, (x, y), (x + w, y + h), (255, 255, 0), 2)

            face = image[y:y + w,
                         x:x + h]  #recortando  imagem atraves do retangulo
            face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)

        cv2.imwrite(path_facepp, face)

        facepp = cv2.imread(path_facepp, cv2.CV_LOAD_IMAGE_GRAYSCALE)
        img = pp.preproc(facepp)

        # Salvar imagem
        cv2.imwrite(path_facepp, img)  # foto preta

        cv2.imshow('face pre process', img)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

        print(img)

        # # Features
        # rows = 0

        # # 2D image --->>>  1D image
        # for j in xrange(0, size_cols):