Ejemplo n.º 1
0
def plot2d(data, cmap='gray_r', **kwargs):
    
    #if datax.ndim != datay.ndim: 
    #    print "data set sizes don't match!"
    #    return 0

    #num = np.arange(0, datax.ndim, 1)

    #f, axarr = plt.subplots(datax.ndim)
    #for n in num: 
    #    axarr[n].plot(datax[n], datay[n])
    #    axarr[n].set_title

    for name, value in kwargs.items(): 
        print "%s = %f" %(name, value)
    
    plt.figure()
    plt.imgshow(kwargs['img'], cmap=kwargs['cmap'] )
Ejemplo n.º 2
0
from app import filtroFauna, filtroFlora
from PIL import Image
from matplotlib import pyplot as plt

imgFlora = Image.open("img/floresta-amazonia.jpg")
resfl = filtroFlora(imgFlora)
plt.imshow(resfl)
plt.show()
imgFauna = Image.open("img/arara-azul-voando.jpg")
resfa = filtroFauna(imgFauna)
plt.imshow(resfa)
plt.show()

# Juntando imagens.

plt.imgshow(resfa, resfl)
Ejemplo n.º 3
0
val_loss = autoencoder_train.history['val_loss']
epochs = range(epochs)
plt.figure()

plt.plot(epochs, loss, 'bo', label='Training loss')
plt.plot(epochs, val_loss, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()

pred = autoencoder.predict(test_data)
print(pred.shape)

plt.figure(figsize=(20, 4))
print("Test Images")
for i in range(10):
    plt.subplot(2, 10, i + 1)
    plt.imshow(test_data[i, ..., 0], cmap='gray')
    curr_lbl = test_labels[i]
    plt.title("(Label: " + str(label_dict[curr_lbl]) + ")")

plt.show()
plt.figure(figsize=(20, 4))
print("reconstruction of test images")
for i in range(10):
    plt.subplot(2, 10, i + 1)
    plt.imgshow(pred[i, ..., 0], cmap='gray')

import pylab as p
p.show()
Ejemplo n.º 4
0
	def plot(self):
		plt.imgshow(self.image, cmap=plt.cm.gray)
		plt.axis('off')
		plt.show()
Ejemplo n.º 5
0
import pylab as pl

digits = load_digits()

#Analyzing one image.
pl.gray()
pl.matshow(digits.images[0])
pl.show()

#Visualizing first 15 images with their labels.
data = list(zip(digits.images, digits.target))
plt.figure(figsize=(5, 5))
for item, (img, label) in enumerate(data[:15]):
    plt.subplot(3, 5, item + 1)
    plt.axis('off')
    plt.imgshow(img, cmap=plt.cm.gray_r, interpolation='nearest')
    plt.tittle('%i' % label)

import random
from sklean import ensemble

#Dividing our data in order to use it as a supervised learning.
n = len(digits.images)
x = digits.images.reshape((n, -1))
y = digits.target

#Random indices.
sample_index = random.sample(range(len(x)), len(x) / 5)
valid_index = [i for i in range(len(x)) if i not in sample_index]

#Images and targets to work.
Este é um arquivo de script temporário.
"""

#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np

#%%
img = cv2.imread('onepiece.jpeg', cv2.IMREAD_GRAYSCALE)
plt.imshow(img, cmap='gray')

#%%
img = cv2.imread('onepiece.jpeg', cv2.IMREAD_GRAYSCALE)
img = cv2.cvtColor(img, cv2.IMREAD_COLOR)
plt.imshow(img)

#%%
rgb = cv2.split(img)
plt.subplot(221), plt.imgshow(img)
plt.subplot(222), plt.title('R'), plt.imshow(rgb[0], cmap='gray')
plt.subplot(223), plt.title('G'), plt.imshow(rgb[1], cmap='gray')
plt.subplot(224), plt.title('B'), plt.imshow(rgb[2], cmap='gray')
plt.show()

#%%
img = cv2.imread('download.jpeg', cv2.IMREAD_GRAYSCALE)
plt.subplot(221), plt.title('Original'), plt.imshow(img, cmap='gray')
plt.subplot(222), plt.title('Histogram'), plt.hist(img.ravel(), 256, [0, 256])
plt.show()
Ejemplo n.º 7
0
        image = tf.convert_image_dtype(image, dtype=tf.float32)
    bbox_begin,bbox_size,_ = tf.image.sample_distorted_bounding_box(tf.shape(image),bounding_boxes=bbox)#随机截取图像
	
    distort_image = tf.slice(image, bbox_begin, bbox_size)
	distorted_image = tf.image.resize_images(distort_image,[height,width],method=np.randint(4))#调整图像大小为神经网络的输入大小
    distort_image = tf.image.random_flip_left_right(distort_image)#随机左右翻转图像
    distort_image = distort_color(distort_image,np.random.randint(2))#随机调整图像颜色
    return distort_image

image_raw_data = tf.gfile.FastGFile(path,'rb').read()
with tf.Session() as sess:
    image_data = tf.image.decode(image_raw_data)
    boxes = tf.constant([[[0.05,0.05,0.9,0.7],[0.35,0.47,0.5,0.56]]])
    for i in range(6)
        result = preprocess_for_train(image_data,299,299,boxes)
        plt.imgshow(result.eval())
        plt.show()

多线程处理数据输入

队列,处理输入数据的框架
import tensorflow as tf

q = tf.FIFOQueue(2,'int32')#指定一个先进先出队列,可以保存两个元素
#RandomShufffleQueue是随机进出队列
init = q.enqueue_many(([0,10],))#使用函数初始化队列中的元素,元素的值为0和10
x = q.dequeue()#出队列
y = x + 1
q_inc = q.enqueue([y])#加入队列
with tf.Session() as tf:
    init.run()#初始化队列
Ejemplo n.º 8
0
    #plt.plot(resnet18.TEST_LOSS, label="Testing Loss ResNet18")
    #plt.legend()
    #plt.savefig(os.path.join("plots", "final_loss.png"))
    #plt.show()

    #plt.figure(figsize=(12, 8))
    #plt.title("Accuracy")
    #plt.plot(model21.VALIDATION_ACC, label="Validation Accuracy Model 21")
    #plt.plot(model21.TRAIN_ACC, label="Training Accuracy Model 21")
    #plt.plot(model21.TEST_ACC, label="Testing Accuracy Model 21")
    #plt.plot(resnet18.VALIDATION_ACC, label="Validation Accuracy ResNet18")
    #plt.plot(resnet18.TRAIN_ACC, label="Training Accuracy ResNet18")
    #plt.plot(resnet18.TEST_ACC, label="Testing Accuracy ResNet18")
    #plt.legend()
    #plt.savefig(os.path.join("plots", "final_accuracy.png"))
    #plt.show()

    #Visualizing filters
    to_vis = resnet18.visualize_first_filter_resnet18()
    plt.imgshow(to_vis)
    plt.savefig(os.path.join("plots", "first_layer_filters.png"))
    plt.show()

    #print("Final test accuracy:", trainer.TEST_ACC[-trainer.early_stop_count])
    #print("Final test loss:", trainer.TEST_LOSS[-trainer.early_stop_count])
    #print("Final validation accuracy:", trainer.VALIDATION_ACC[-trainer.early_stop_count])
    #print("Final validation loss:", trainer.VALIDATION_LOSS[-trainer.early_stop_count])
    #print("Final ttaining accuracy:", trainer.TRAIN_ACC[-trainer.early_stop_count])
    #print("Final training loss:", trainer.TRAIN_LOSS[-trainer.early_stop_count])
    #print("Total number of epochs " + str(trainer.number_of_epochs))
Ejemplo n.º 9
0
def plot_digit(X,y,idx):
  img = X[idx].reshape(28,28)
  plt.imgshow(img,cmap="Greys")
  plt.show()
Ejemplo n.º 10
0
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import fetch_mldata

dataset = fetch_mldata('MNIST original')

X = dataset.data
y = dataset.target

some_digit = X[62302]
some_digit_image = some_digit_reshape(28, 28)

plt.imgshow(some_digit_image)
plt.show()

from sklearn.tree import DecisionTreeClassifier
dtf = DecisionTreeClassifier()
dtf.fit(X, y)

dtf.score(X, y)

dtf.predict(X[[17,2703, 13413, 56404, 62302], ])

from sklearn.tree import export_graphviz

export_graphviz(dtf, out_file="tree.dot")

import graphviz
with open("tree.dot") as f:
dot_graph = f.read()
Ejemplo n.º 11
0
# Resimdeki ana hatların ortaya çıkarılması sağlanır.

import cv2
import matplotlib.pyplot as plt

# Resmi içeri aktarma
img = cv2.imread("image1.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  #GrayScale convert

# Thresh ile maxval arasındaki değerler beyaz olur.
# cv2.THRESH_BINARY_INV uygulanırsa tam tersi olur. Yani beyaz yerine siyah olur.
_, thresh_img = cv2.threshold(img,
                              thresh=60,
                              maxval=255,
                              type=cv2.THRESH_BINARY)

# Uyarlamalı eşik değeri
# Bir dağ resminde bazı bölgerine ışık az düşer ise o bölge koyu renk olur.
# Bu algoritmada dağı bir bütün olarak algılar ve renk dağılımını eşit uygular.
thresh_img2 = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
                                    cv2.THRESH_BINARY, 11, 8)

#Görselleştirme
plt.figure()
plt.imgshow(thresh_img2, cmap="gray ")
plt.axis("off")  #eksenler kapanır.
plt.show()