Code Monkey home page Code Monkey logo

Comments (2)

jstoecker avatar jstoecker commented on September 12, 2024 1

Interesting that we didn't include that op in the PyDirectML bindings, but we do have activation_identity (more or less the same as identity but no scale or bias allowed). Try this:

import pydirectml as dml
import numpy as np

input_data = [
    [1,2,3],
    [4,5,6]
]

device = dml.Device(True, True)
builder = dml.GraphBuilder(device)

input_desc = dml.TensorDesc(dml.TensorDataType.FLOAT32, (1,1,2,3), (6,6,3,1))
input = dml.input_tensor(builder, 0, input_desc)
input_identity = dml.activation_identity(input)

input_transposed = dml.activation_identity(
    dml.reinterpret(input_identity, dml.TensorDataType.FLOAT32, (1,1,3,2), (6,6,1,3)))

input_broadcast = dml.activation_identity(
    dml.reinterpret(input_identity, dml.TensorDataType.FLOAT32, (1,1,6,3), (0,0,0,1)))

op = builder.build(dml.ExecutionFlags.NONE, [input_identity, input_transposed, input_broadcast])

input_bindings = (dml.Binding(input, input_data),)
output_data = device.compute(op, input_bindings, [input_identity, input_transposed, input_broadcast])

print(f"\nOriginal:\n{np.array(output_data[0], np.float32)}")
print(f"\nTransposed:\n{np.array(output_data[1], np.float32)}")
print(f"\nBroadcast First Row:\n{np.array(output_data[2], np.float32)}")

Output

Original:
[[[[1. 2. 3.]
   [4. 5. 6.]]]]

Transposed:
[[[[1. 4.]
   [2. 5.]
   [3. 6.]]]]

Broadcast First Row:
[[[[1. 2. 3.]
   [1. 2. 3.]
   [1. 2. 3.]
   [1. 2. 3.]
   [1. 2. 3.]
   [1. 2. 3.]]]]

from directml.

huningxin avatar huningxin commented on September 12, 2024

Thanks @jstoecker , your sample code solves my use case. I have no issues now. Close this one.

from directml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.