Giter VIP home page Giter VIP logo

Comments (4)

sushreebarsa avatar sushreebarsa commented on July 28, 2024

@myh1234567
Could you please verify that all input data (x, y, etc.) passed to your model is of the correct type (tf.float32, tf.float64, etc.) as expected by the model's architecture and the loss function ? Also, in order to expedite the trouble-shooting process, please provide a code snippet to reproduce the issue reported here. Thank you!

from tensorflow.

myh1234567 avatar myh1234567 commented on July 28, 2024

@myh1234567 Could you please verify that all input data (x, y, etc.) passed to your model is of the correct type (tf.float32, tf.float64, etc.) as expected by the model's architecture and the loss function ? Also, in order to expedite the trouble-shooting process, please provide a code snippet to reproduce the issue reported here. Thank you!

the following is the code snippent,

import tensorflow as tf
import numpy as np
import scipy.sparse as sp
import keras
from keras.utils import to_categorical

physical_device = tf.config.list_physical_devices("GPU")
print("===================================== num gpu:", len(physical_device))

def convert_sparse_matrix_to_sparse_tensor(X) -> tf.SparseTensor:
""" Convert a scipy sparse matrix to a SparseTensor."""
coo = X.tocoo()
indices = np.mat([coo.row, coo.col]).transpose()
return tf.sparse.SparseTensor(indices, coo.data, coo.shape)

X_transformed_train_db = sp.rand(100, 1000, density=0.1, format='coo')
X_train_db = convert_sparse_matrix_to_sparse_tensor(X_transformed_train_db)
X_train_db = tf.sparse.reorder(X_train_db)
y_train_db = np.random.randint(0, 3, size=(100,)) # Let's assume 3 classes
y_train_db_ = to_categorical(y_train_db)

gpus = tf.config.list_logical_devices("GPU")
strategy = tf.distribute.MirroredStrategy(gpus)

with strategy.scope():
opti = keras.optimizers.Adam(learning_rate=0.0001)
input_dimension = X_transformed_train_db.shape[1]
model_db = keras.Sequential()
model_db.add(keras.layers.Dense(1000, kernel_initializer=keras.initializers.HeNormal(seed=1), activation='relu', input_dim=input_dimension))
model_db.add(keras.layers.Dropout(0.1))
model_db.add(keras.layers.Dense(500, kernel_initializer=keras.initializers.HeNormal(seed=2), activation='relu'))
model_db.add(keras.layers.Dropout(0.1))
model_db.add(keras.layers.Dense(200, kernel_initializer=keras.initializers.HeNormal(), activation='relu'))
model_db.add(keras.layers.Dropout(0.1))
model_db.add(keras.layers.Dense(y_train_db_.shape[1], kernel_initializer=keras.initializers.RandomNormal(mean=0.0, stddev=0.05, seed=4), activation='softmax'))
model_db.compile(optimizer=opti, loss='categorical_crossentropy',metrics=['accuracy'])

history_db = model_db.fit(X_transformed_train_db, y_train_db_, epochs=3)

tensorflow 2.16.1
keras 3.3.3
scipy 1.13.1
numpy 1.26.4

thank you

from tensorflow.

tilakrayal avatar tilakrayal commented on July 28, 2024

@myh1234567 ,
I tried to execute the code and faced the indentation errors. Could you please provide colab gist or the executable way. And also could you please confirm this issue is happening with tensorflow 2.15 as well because, 2.15 contains keras2.0 and 2.16 contains keras3.0. Thank you!

from tensorflow.

myh1234567 avatar myh1234567 commented on July 28, 2024

@myh1234567 , I tried to execute the code and faced the indentation errors. Could you please provide colab gist or the executable way. And also could you please confirm this issue is happening with tensorflow 2.15 as well because, 2.15 contains keras2.0 and 2.16 contains keras3.0. Thank you!

https://colab.research.google.com/gist/myh1234567/a83605d7c47314f6a9a5ced2807f4fde/63362.ipynb

from tensorflow.

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.