Exemple #1
0
input_bindings = []

def append_input_tensor(builder: dml.GraphBuilder, input_bindings: list, input_tensor: dml.TensorDesc, file_name: str):
    tensor = dml.input_tensor(builder, len(input_bindings), input_tensor)
    if file_name == "":
        input_bindings.append(dml.Binding(tensor, np.zeros(tensor.get_output_desc().sizes)))
    else:
        input_bindings.append(dml.Binding(tensor, np.load(tensor_data_path + "/" + file_name)))
    return tensor

# Create a GPU device, and build a model graph.
device = dml.Device(True, True)
builder = dml.GraphBuilder(device)

data_type = dml.TensorDataType.FLOAT32
input = dml.input_tensor(builder, 0, dml.TensorDesc(data_type, [1, 1, 28, 28]))
flags = dml.TensorFlags.OWNED_BY_DML

input_bindings.append(dml.Binding(input, rescaled_image))

# convolution28
convolution28_weight = append_input_tensor(builder, input_bindings, dml.TensorDesc(data_type, flags, [8, 1, 5, 5]), "Parameter5.npy")
convolution28_bias = append_input_tensor(builder, input_bindings, dml.TensorDesc(data_type, flags, [1, 8, 1, 1]), "")
convolution28 = dml.convolution(input, convolution28_weight, convolution28_bias, strides = [1, 1], start_padding = [2, 2], end_padding = [2, 2])

# plus30
plus30_param6 = append_input_tensor(builder, input_bindings, dml.TensorDesc(data_type, [1, 8, 28, 28], [8, 1, 0, 0]), "Parameter6.npy")
plus30 = dml.add(convolution28, plus30_param6)

# relu32
relu32 = dml.activation_relu(plus30)
Exemple #2
0
image = ImageOps.fit(image, (720, 720),
                     method=0,
                     bleed=0,
                     centering=(0.5, 0.5))

image_tensor = np.array(image, np.float32)

transposed_image = np.transpose(image_tensor, axes=[2, 0, 1])

# Create a GPU device and build a model graph.
device = dml.Device(True, True)
builder = dml.GraphBuilder(device)

data_type = dml.TensorDataType.FLOAT32
input = dml.input_tensor(builder, 0, dml.TensorDesc(data_type,
                                                    [1, 3, 720, 720]))
flags = dml.TensorFlags.OWNED_BY_DML

# scalar1
scaler1_bias = [-103.93900299072266, -116.77899932861328, -123.68000030517578]
scaler1 = dml.value_scale_2d(input, 1.0, scaler1_bias)

# pad3
pad3 = dml.padding(scaler1, dml.PaddingMode.REFLECTION, 0.0, [0, 0, 40, 40],
                   [0, 0, 40, 40])

# conv4
conv4_filter = dml.input_tensor(
    builder, 1, dml.TensorDesc(data_type, flags, [16, 3, 9, 9]))
conv4_bias = dml.input_tensor(builder, 2,
                              dml.TensorDesc(data_type, flags, [1, 16, 1, 1]))
Exemple #3
0
img = ImageOps.fit(img, (224, 224), method=0, bleed=0, centering=(0.5, 0.5))

img_ycbcr = img.convert('YCbCr')
img_y_0, img_cb, img_cr = img_ycbcr.split()
img_ndarray = np.asarray(img_y_0)

img_4 = np.expand_dims(np.expand_dims(img_ndarray, axis=0), axis=0)
img_5 = img_4.astype(np.float32) / 255.0

# Create an executing device and build a model
device = dml.Device(True, True)
builder = dml.GraphBuilder(device)

data_type = dml.TensorDataType.FLOAT32
input = dml.input_tensor(builder, 0,
                         dml.TensorDesc(data_type, [batch_size, 1, 224, 224]))
flags = dml.TensorFlags.OWNED_BY_DML

# conv1
conv1_filter = dml.input_tensor(
    builder, 1, dml.TensorDesc(data_type, flags, [64, 1, 5, 5]))
conv1_bias = dml.input_tensor(builder, 2,
                              dml.TensorDesc(data_type, flags, [1, 64, 1, 1]))
conv1 = dml.convolution(input,
                        conv1_filter,
                        conv1_bias,
                        start_padding=[2, 2],
                        end_padding=[2, 2],
                        fused_activation=dml.FusedActivation(
                            dml.OperatorType.ACTIVATION_RELU))
Exemple #4
0
    tensor = dml.input_tensor(builder, len(input_bindings), input_tensor)
    if file_name == "":
        input_bindings.append(
            dml.Binding(tensor, np.zeros(tensor.get_output_desc().sizes)))
    else:
        input_bindings.append(
            dml.Binding(tensor, np.load(tensor_data_path + "/" + file_name)))
    return tensor


# Create a GPU device, and build a model graph.
device = dml.Device(True, True)
builder = dml.GraphBuilder(device)

data_type = dml.TensorDataType.FLOAT32
input = dml.input_tensor(builder, 0, dml.TensorDesc(data_type,
                                                    [1, 3, 224, 224]))
flags = dml.TensorFlags.OWNED_BY_DML

input_bindings.append(dml.Binding(input, processed_image))

# squeezenet0_conv0_fwd
squeezenet0_conv0_weight = append_input_tensor(
    builder, input_bindings, dml.TensorDesc(data_type, flags, [64, 3, 3, 3]),
    "squeezenet0_conv0_weight.npy")
squeezenet0_conv0_bias = append_input_tensor(
    builder, input_bindings, dml.TensorDesc(data_type, flags, [1, 64, 1, 1]),
    "squeezenet0_conv0_bias.npy")
squeezenet0_conv0_fwd = dml.convolution(input,
                                        squeezenet0_conv0_weight,
                                        squeezenet0_conv0_bias,
                                        strides=[2, 2],
Exemple #5
0
    sys.exit(1)

image = Image.open(image_file_path)

image = ImageOps.fit(image, (720, 720), method = 0,  bleed = 0, centering = (0.5, 0.5))

image_tensor = np.array(image, np.float32)

transposed_image = np.transpose(image_tensor, axes=[2,0,1])

# Create a GPU device and build a model graph.
device = dml.Device(True, True)
builder = dml.GraphBuilder(device)

data_type = dml.TensorDataType.FLOAT32
input = dml.input_tensor(builder, 0, dml.TensorDesc(data_type, [1, 3, 720, 720]));
flags = dml.TensorFlags.OWNED_BY_DML

# scalar1
scaler1_bias = [-103.93900299072266, -116.77899932861328, -123.68000030517578]
scaler1 = dml.value_scale_2d(input, 1.0, scaler1_bias)

# pad3
pad3 = dml.padding(scaler1, dml.PaddingMode.REFLECTION, 0.0, [0, 0, 40, 40], [0, 0, 40, 40])

# conv4
conv4_filter = dml.input_tensor(builder, 1, dml.TensorDesc(data_type, flags, [16,3,9,9]))
conv4_bias = dml.input_tensor(builder, 2, dml.TensorDesc(data_type, flags, [1,16,1,1]))
conv4 = dml.convolution(pad3, conv4_filter, conv4_bias, start_padding = [4,4], end_padding = [4,4])

# instance_norm5