Row 2209
Content Data
This page contains data entry 2209 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.
I am trying to re write some code in tensorflow, which was originally written in pytorch, but have attempted everything, including writting my own code based on theory rather than just changing the functions from one framework to another. I have also attempted using chatgpt and it didnt give me proper results. I have written some code now but I keep getting the error mentioned above (will write the full error message in the comments). Here is both the working pytorch code and the failing tensorflow code. Is there any idea of what I could be doing wrong or what I could do? It doesnt help that anything I try to fix the error doesnt work.
# pytorch code def forward(self, X):
B = torch.tensor_split(X, self.idxs, dim=3) Z = []
for i, (layer_norm, linear_layer) in enumerate(zip(self.layer_norms, self.linear_layers)): b_i = torch.cat((B[i][:, :, 0, :, :],B[i][:, :, 1, :, :]), 2) #concatenate real and imaginary spectrograms b_i = torch.transpose(layer_norm(b_i), 2, 3) #mirar be com es fa la layer norm Z.append(torch.transpose(linear_layer(b_i), 2, 3))
Z = torch.stack(Z, 3) return Z
# Tensorflow Code def call(self, inputs): B = tf.split(inputs, self.idxs.numpy(), axis=3) Z = []
for i, (layer_norm, linear_layer) in enumerate(zip(self.layer_norms, self.linear_layers)): b_i = tf.concat([B[i][:, :, :, :, 0], B[i][:, :, :, :, 1]], axis=2) b_i = tf.transpose(layer_norm(b_i), perm=[0, 1, 3, 2]) Z.append(tf.transpose(linear_layer(b_i), perm=[0, 1, 3, 2]))
Z = tf.stack(Z, axis=3) return Z
I am trying to run it on the following code, which works in pytorch, but not tensorflow:
# Test run B = 1 T = 1 C = 1 F = 1 X = tf.random.normal(shape=(B, T, C, F)) band_split = Band_Split(temporal_dimension, max_freq_idx, sample_rate, n_fft, subband_dim) result = band_split(X)
print(X.shape) # output is ([1, 2, 2, 257, 100]) print(result.shape) # output is ([1, 2, 128, 30, 100]) on pytorch, tf does not work
| Field | Value |
|---|---|
| text | I am trying to re write some code in tensorflow, which was originally written in pytorch, but have attempted everything, including writting my own code based on theory rather than just changing the functions from one framework to another. I have also attempted using chatgpt and it didnt give me proper results. I have written some code now but I keep getting the error mentioned above (will write the full error message in the comments). Here is both the working pytorch code and the failing tensorf… |
| label | r/tensorflow |
| dataType | post |
| communityName | r/tensorflow |
| datetime | 2023-07-17 |
| username_encoded | Z0FBQUFBQm5LakwwTWhXRzJSZWh4b1IwSnU1Q2h1cmdZTktXNlV3ZmZGaXpDdDRVRXBHQU9KdjhmLUNrd201UGx4cHU2clY4d2lZNnF2eWdScHJVMV9tc0UwWW0wNi1qMGc9PQ== |
| url_encoded | Z0FBQUFBQm5Lak9FVmlBbjlVMzl4QlBQV1N6WVdqdXh2VTJHUUV3SzNXZGFJb2xhelQyaWdiYTdJdlpLZHlmNWRnVVJ0SG94cVEzSXVSWnByZE1yVXJyNU1YdEVqbVNucHFUZGxfZkk2elVDNlFRTGNHSXFtN3d4cjFRQnBHWVRqRFkxQWFyazRKVkpfbUFZblcyYVdDWE03VW9MU0ZFOUVLUGxTcmlBdlowTTE1aElnbFJsMklxeWR6aWRUbm1rdG5BTjFrRlNCdTJrcElTWEhZcEpjZnFROWJwOExrcGpoUT09 |
Raw Record
{
"text": "I am trying to re write some code in tensorflow, which was originally written in pytorch, but have attempted everything, including writting my own code based on theory rather than just changing the functions from one framework to another. I have also attempted using chatgpt and it didnt give me proper results. I have written some code now but I keep getting the error mentioned above (will write the full error message in the comments). Here is both the working pytorch code and the failing tensorflow code. Is there any idea of what I could be doing wrong or what I could do? It doesnt help that anything I try to fix the error doesnt work.\n\n # pytorch code\n def forward(self, X):\n\n B = torch.tensor_split(X, self.idxs, dim=3)\n Z = []\n\n for i, (layer_norm, linear_layer) in enumerate(zip(self.layer_norms, self.linear_layers)):\n b_i = torch.cat((B[i][:, :, 0, :, :],B[i][:, :, 1, :, :]), 2) #concatenate real and imaginary spectrograms\n b_i = torch.transpose(layer_norm(b_i), 2, 3) #mirar be com es fa la layer norm\n Z.append(torch.transpose(linear_layer(b_i), 2, 3))\n\n\n Z = torch.stack(Z, 3)\n return Z\n\n # Tensorflow Code\n def call(self, inputs):\n B = tf.split(inputs, self.idxs.numpy(), axis=3)\n Z = []\n\n for i, (layer_norm, linear_layer) in enumerate(zip(self.layer_norms, self.linear_layers)):\n b_i = tf.concat([B[i][:, :, :, :, 0], B[i][:, :, :, :, 1]], axis=2)\n b_i = tf.transpose(layer_norm(b_i), perm=[0, 1, 3, 2])\n Z.append(tf.transpose(linear_layer(b_i), perm=[0, 1, 3, 2]))\n\n Z = tf.stack(Z, axis=3)\n return Z\n\n\n\nI am trying to run it on the following code, which works in pytorch, but not tensorflow:\n\n\n # Test run\n B = 1\n T = 1\n C = 1\n F = 1\n X = tf.random.normal(shape=(B, T, C, F))\n band_split = Band_Split(temporal_dimension, max_freq_idx, sample_rate, n_fft, subband_dim)\n result = band_split(X)\n\nprint(X.shape) # output is ([1, 2, 2, 257, 100])\nprint(result.shape) # output is ([1, 2, 128, 30, 100]) on pytorch, tf does not work",
"label": "r/tensorflow",
"dataType": "post",
"communityName": "r/tensorflow",
"datetime": "2023-07-17",
"username_encoded": "Z0FBQUFBQm5LakwwTWhXRzJSZWh4b1IwSnU1Q2h1cmdZTktXNlV3ZmZGaXpDdDRVRXBHQU9KdjhmLUNrd201UGx4cHU2clY4d2lZNnF2eWdScHJVMV9tc0UwWW0wNi1qMGc9PQ==",
"url_encoded": "Z0FBQUFBQm5Lak9FVmlBbjlVMzl4QlBQV1N6WVdqdXh2VTJHUUV3SzNXZGFJb2xhelQyaWdiYTdJdlpLZHlmNWRnVVJ0SG94cVEzSXVSWnByZE1yVXJyNU1YdEVqbVNucHFUZGxfZkk2elVDNlFRTGNHSXFtN3d4cjFRQnBHWVRqRFkxQWFyazRKVkpfbUFZblcyYVdDWE03VW9MU0ZFOUVLUGxTcmlBdlowTTE1aElnbFJsMklxeWR6aWRUbm1rdG5BTjFrRlNCdTJrcElTWEhZcEpjZnFROWJwOExrcGpoUT09"
}
Entry Information
- Entry ID: 2209
- Repository: Axioma AXP
- Dataset: arrmlet/reddit_dataset_36
- Total Entries: 100,000