Пример #1
0
 def run_forward_pass(state):
     # expand the dimensions of the state, allowing it to be fed into
     # our net
     state = np.expand(state, axis=0)
     # make prediction for value function of given state
     value = self.value_approximator.predict(state)
     return value
def process_array(image_array, expand=True):
    '''process a 3d array into a scaled, 4d batch of size 1'''
    #   image_batch = image_array/255.0
    if expand:
        image_batch = np.expand(image_array, axis=0)
        return image_batch
    else:
        return image_array
def minibatch(input, num_kernels=5, kernel_dim=3):

    # this shared variable will have dimensions 4 * 15
    x = theano.shared(input, num_kernels * kernel_dim, dtype='float32')
    print(x.shape)
    #  reshaped to 5 *
    activation = np.reshape(x, (-1, num_kernels, kernel_dim))
    print(activation.shape)
    diffs = (np.expand_dims(activation, 3) -
             np.expand(T.transpose(activation, [1, 2, 0], 0)))
    abs_diffs = T.sum(T.abs_(diffs), axis=2)
    minibatch_features = T.sum(T.exp(-abs_diffs), 2)
    return T.concatenate([input, minibatch_features], axis=1)
Пример #4
0
def expand_dims(array,axis=0,normalize=False):
    """Expand the shape of an array.

    Insert a new axis that will appear at the `axis` position in the expanded
    array shape.

    Parameters
    ----------
    array : numpy array.
    axis : int or tuple of ints
    Position in the expanded axes where the new axis is placed
    normalize: 
        True : return normalized image
        False : return just image array with expanded dimensions 
    """
    array = expand(array,axis=axis)
    if normalize:
        array /= 255.
    return array
from keras.models import Model
from keras.preprocessing import image
from keras.optimizers import Adam
from keras.applications.vgg16 import VGG16
import matplotlib.pyplot as plt
import numpy as np
import cv2
'''prebuilt model eith prebuilt weights on imagenet'''
model = VGG16(weights='imagenet', include_top=True)
Adam = Adam(lr=0.1, decay=1e-6,
            epsilon=1e-6)  #lr=10**-3, decay=1e-7, epsilon=1e-6
model.compile(optimizer=Adam, loss='categorical_crossentropy')
'''resize into VGG16 trained images format'''
im = cv2.resize(cv2.imread('vlcsnap-2019-02-24-21h26m43s779.png', ))
im = np.expand(im, axis=0)
'''predict'''
out = model.predict(im)
plt.plot(out.ravel())
plt.show()
print(np.argmax(out))
Пример #6
0
def get_embedding(part_image, face_descriptor, dropout_rate=0.5):
    input_data = [np.expand(part_image, axis=0), dropout_rate]
    prediction = face_descriptor.inference(data=input_data)
    return prediction