예제 #1
0
파일: train.py 프로젝트: mataiscat/CodeFun
def gen_train_val_data(sample_dir, train_rate, num_classes, condition_classes):
    train_data, train_label, valid_data, valid_label, train_n, valid_n, note_label = load_image(sample_dir, 1.0).gen_train_valid()
    train_data_trip = create_pairs(train_data, num_classes, condition_classes)
    train_num = int(train_n*train_rate)
    train_data_trip = train_data_trip[0:train_num]
    val_data_trip = train_data_trip[-train_num:-1]
    test_data_trip = val_data_trip
    return train_data_trip, val_data_trip, test_data_trip
def main():

    print(df)

    for index, row in df.iterrows():
        img = load_image(row['image_name'] + '.tif')
        print(type(img))  #np.ndarray
        print(img.shape)
        print(row['image_name'])
        r, g, b, nir = img[:, :, 0], img[:, :, 1], img[:, :, 2], img[:, :, 3]
        fig = plt.figure()
        fig.set_size_inches(12, 4)
        for i, (x, c) in enumerate(
            ((r, 'r'), (g, 'g'), (b, 'b'), (nir, 'near-ir'))):
            a = fig.add_subplot(1, 4, i + 1)
            a.set_title(c)
            plt.imshow(x)
            plt.gray()
        plt.show()
        if index > 1: break
    Y_train = df['tags'].values
예제 #3
0
"""
    Created on 2017 10.17
    @author: liupeng
    """

import sys
import tensorflow as tf
import numpy as np
import os
import cv2
from skimage import exposure
from data_load import load_image

# 图片在二级目录
file_path = 'gender'
img_path, _, _, _, _, _, _ = load_image(file_path, 1.0).gen_train_valid()
print(img_path)


def add_img_padding(img):
    h, w, _ = img.shape
    width = np.max([h, w])
    # 按照长宽中大的初始化一个正方形
    img_padding = np.zeros([width, width, 3])
    # 找出padding的中间位置
    h1 = int(width / 2 - h / 2)
    h2 = int(width / 2 + h / 2)
    w1 = int(width / 2 - w / 2)
    w2 = int(width / 2 + w / 2)
    # 进行padding, img为什么也要进行扣取? 原因在于除以2取整会造成尺寸不一致的情况。
    img_padding[h1:h2, w1:w2, :] = img[0:(h2 - h1), 0:(w2 - w1), :]
예제 #4
0
# coding: utf-8

import pandas as pd
import numpy as np
import data_load
import feature_extract

from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import KernelPCA
from sklearn

if __name__=="__main__":
    train_df = data_load.load_train()
    train_df = train_df.sample(40)
    X = [ data_load.load_image(row.image_name + ".jpg") for i, row in train_df.iterrows()]
    hog_X = np.array([ feature_extract.hog_cnl(x) for x in X ])
    y = np.array([ row.tags for i, row in train_df.iterrows()])
    print(hog_X.shape)
    print(y.shape)

    X_dev, X_val, y_dev, y_val = train_test_split(hog_X, y, test_size=0.2)

    pipe = Pipeline([('sc', StandardScaler()),
            ('pca', KernelPCA(n_components=200, kernel="linear")),
            ('clf', LinearRegression())])