Categories
Misc

Medium-scale TensorFlow project

This is a weird question but I work for a company that sets up HPC clusters and we just finished setting up a cluster that is going to be used for machine learning and video analytics. We would like to test this cluster using a ML job (including training I guess?) that uses a decent enough amount of resources (not too small scale) in order to make sure that everything is working. However, I can’t seem to find what I am looking for online, or maybe I am looking in the wrong places.

Can anyone help or point me in the right direction? I am looking for a job that uses multiple GPUs.

submitted by /u/charles-foster-kane
[visit reddit] [comments]

Categories
Misc

Mirrored strategy distributed training.

Has anyone worked with the tf.distribute.MirroredStrategy? I seem to be getting low model accuracy when using it for image segmentation with Dice loss.

Also saw minor gains in timing when running with 8 gpu setup.

submitted by /u/Ash_real
[visit reddit] [comments]

Categories
Misc

I need help with this question. Can you train a model with sklearn, export it as a pickle object and open that pickle object and use it as the input of TensorFlow Explainable AI tools such as TFMA, What-If Tool, TF Privacy, etc?

Basically the title. I need some sort of guidance here because I have never worked with TensorFlow and I am still not quite sure if TensorFlow and Sklearn can be used in tandem or they are completely independent and can’t be used together.

Thanks!

submitted by /u/piratagitano
[visit reddit] [comments]

Categories
Misc

I was making a GAN to write poem , but got this error

the code:

from google.colab import drive
drive.mount(‘/content/drive’)
from google.colab import files
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
import numpy as np
import string
from tensorflow.keras.utils import to_categorical
import os
from tensorflow.keras import regularizers
import pickle
import sys
from tensorflow.keras.preprocessing.sequence import pad_sequences
import tensorflow as tf
from tensorflow.keras.layers import Dense, SimpleRNN, Embedding,GRU,Flatten,LSTM,Conv2D,MaxPool2D,Dropout,ConvLSTM2D,Reshape
from tensorflow.keras.models import Sequential
from tensorflow.keras.utils import to_categorical
def clean_text(text):
words = text.split()
table = str.maketrans(”,”, string.punctuation)
words = [w.translate(table) for w in words]
words = [word for word in words if word.isalpha()]
return words
def generate_sequences(words):
length = 10 + 1
sentences = []
for i in range(length, len(words)):
seq = words[i-length:i]
line = ‘ ‘.join(seq)
sentences.append(line)
return sentences
def process_data(path):
raw_data = open(path, ‘r’, encoding=’utf-8′).read()
lower_text = raw_data.lower()
words = clean_text(lower_text)
sentences = generate_sequences(words)
return sentences
def create_training_data(tokenizer, numeric_sentences):
vocabulary_size = len(tokenizer.word_index) + 1
data_array = np.array(numeric_sentences)
X, y = data_array[:,:-1], data_array[:,-1]
y = to_categorical(y, num_classes=vocabulary_size)
input_length = X.shape[1]
return X, y, vocabulary_size,input_length
def build_rnn_model(vocabulary_size,input_length):

model = Sequential()
model.add(Embedding(vocabulary_size, 50, input_length = input_length))
model.add(Dense(50,activation=’relu’))
model.add(Dense(75,activation=’relu’))
model.add(LSTM(25, return_sequences=True))
model.add(SimpleRNN(25))
model.add(Dense(50,activation=’relu’))
model.add(Dense(vocabulary_size, activation=’softmax’))
return model
def train(model, batch_size, epochs, learning_rate,X,y):
optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate)
model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer = optimizer, metrics=[‘accuracy’])
with tf.GradientTape() as tape:
pred=model(X)
loss = tf.keras.losses.CategoricalCrossentropy()(y, pred)
grads = tape.gradient(loss, model.trainable_variables)
optimizer.apply_gradients(zip(grads, model.trainable_variables))
history = model.fit(X,y,batch_size=batch_size,epochs=epochs)
return history, model
from pickle import dump
path = ‘data.txt’
sentences = process_data(path)
from tensorflow.keras.preprocessing.text import Tokenizer
def tokenize_sentence(sentences):
tokenizer = Tokenizer()
tokenizer.fit_on_texts(sentences)
numeric_sentences = tokenizer.texts_to_sequences(sentences)
return tokenizer, numeric_sentences
tokenizer, numeric_sentences = tokenize_sentence(sentences)
X,y,vocabulary_size,input_length = create_training_data(tokenizer, numeric_sentences)
model = build_rnn_model(vocabulary_size,input_length)
print(“Starting the traing of the model: “)
batch_size = 128
epochs = 200
learning_rate = 0.0009
#train(model, batch_size, epochs, learning_rate, X,y)
#dump(tokenizer, open(‘C:/Users/HP/Desktop/poem writer/tokenizer.pkl’, ‘wb’))
def poem_generator():
user_input = input(“Write the first line of your poem, the poem generator will complete it!! n>> “)
in_text = user_input.lower()
sys.stdout.write(‘nnYour Poemnn’)
start = ‘ ‘+ in_text+’n’
sys.stdout.write(start)
for i in range(110):
encoded = tokenizer.texts_to_sequences([in_text])[0]
encoded = pad_sequences([encoded], maxlen = input_length, truncating = ‘pre’)
yhat = model.predict(encoded, verbose = 0)
yhat=np.argmax(yhat,axis=1)
out_word = ”
for word, index in tokenizer.word_index.items():
if index == yhat:
out_word = word
break
in_text += ‘ ‘ + out_word
out_word = ‘ ‘ + out_word
if i % 7 ==0 and i !=0:
out_word = out_word + ‘n’
sys.stdout.write(out_word)
sys.stdout.flush()
sys.stdout.write(‘nn’)

with open(‘tokenizer.pkl’ , ‘rb’) as f:
tokenizer = pickle.load(f)
vocabulary_size = len(tokenizer.word_index) + 1
input_length = 10
print(model.summary())
#poem_generator()
def disciminator(inp):
model=Sequential()
model.add(Dense(1285,input_shape=inp))
#model.add(Conv2D(50,1,input_shape=input_shape))
model.add(Dense(75,activation=’relu’))
#model.add(Conv2D(50,1))
model.add(Dense(50,activation=’softmax’))
model.add(Dropout(0.3))
model.add(Dense(10,activation=’sigmoid’))
optimizer = tf.keras.optimizers.Adam(learning_rate=0.0009)
model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer = optimizer, metrics=[‘accuracy’])
return model
def generator():
model = Sequential()
model.add(Embedding(vocabulary_size, 50, input_shape=(vocabulary_size,)))
model.add(Dense(50,activation=’relu’))
model.add(Dense(10,activation=’relu’))
#model.add(LSTM(25,return_sequences=True))
model.add(Dense(50,activation=’relu’))
model.add(Dense(10, activation=’softmax’))
optimizer = tf.keras.optimizers.Adam(learning_rate=0.0009)
model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer = optimizer, metrics=[‘accuracy’])
return model
def gan(gen,dis):
dis.trainable = False
model = Sequential()
model.add(gen)
model.add(dis)
optimizer = tf.keras.optimizers.Adam(learning_rate=0.0009)
model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer = optimizer, metrics=[‘accuracy’])
return model
def generate_real_samp(n_samp):
X1=np.random.randint(0,input_length,vocabulary_size)
x=X[X1]
y=np.ones((vocabulary_size,input_length))
return x.reshape(1285,10),y.reshape(1285,10)
def generate_patien_poi(lat,n_samp):
x_inp=np.random.randn((n_samp**2)*(lat))
x_inp=x_inp.reshape(1285,1285,10)
return x_inp
def cre_fake_po(generator,lat,n_samp):
x_input = generate_patien_poi( n_samp,lat)
x = generator.predict(x_input)
y = np.zeros((3274,10))
return X, y
def trainer(g_model, d_model, gan_model, lat, n_epochs=200, n_batch=128):
h_b=int(n_batch/2)
for i in range(epochs):
x_real,y_real=generate_real_samp(h_b)
print(x_real.shape)
print(y_real.shape)
d_loss1=d_model.fit(x_real,y_real)
x_fake,y_fake=cre_fake_po(g_model,vocabulary_size,input_length)
print(x_fake.shape)
print(y_fake.shape)
d_loss2=d_model.fit(x_fake,y_fake)
x_gan=generate_patien_poi(10,1285)
y_gan=np.ones((1285,1285,10))
x_gan=Reshape((1285,10))(x_gan)
y_gan=Reshape((1285,10))(y_gan)
print(x_gan.shape)
print(y_gan.shape)
g_loss=gan_model.fit(x_gan,y_gan)
d_model.save(“C:/Users/HP/Desktop/poem writer/disci.h5”)
g_model.save(“C:/Users/HP/Desktop/poem writer/generator.h5”)
lat=100
disc=disciminator((10,))
print(disc.summary())
gen=generator()
print(gen.summary())
print(generate_real_samp(64))
print(“********************************************”)
print(generate_real_samp(64)[0].shape)
print(generate_real_samp(64)[1].shape)
gan1=gan(gen,disc)
trainer(gen,disc,gan1,lat)

the error I got:

ValueError: Exception encountered when calling layer “sequential_163” (type Sequential). Input 0 of layer “sequential_161” is incompatible with the layer: expected shape=(None, 10), found shape=(None, 1285, 10, 10) Call arguments received: • inputs=tf.Tensor(shape=(None, 1285, 10), dtype=float32) • training=True • mask=None

How can I solve this problem?

submitted by /u/justahumanlearnspy
[visit reddit] [comments]

Categories
Offsites

The mathematically optimal Wordle strategy

Categories
Misc

How can I solve the following error?

I am a Windows user. I had used Tensorflow lastly 2 years ago to install another library I had had to uninstall Anaconda , Tensorflow and all other libaries.I hhad installed the other library and done what I wanted with it.I had been away from deep learning , machine learing and other things like them for 1 year.It was something like pause.I have started to Tensorflow again recently and wanted install it to the GPU . After dealing with the problems that came because of I had all things uninstalled , I have installed CUDA ,cuDNN and necessary things and runed the code I have written. I have got the error.

tensorflow.python.framework.errors_impl.InternalError: cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version 

I have googled it , but could not find a solution. If you know the solution , can you please explain me?

submitted by /u/justahumanlearnspy
[visit reddit] [comments]

Categories
Misc

How do i do this in my local environment?

Hi,

I was recently going thru a google colab in which they have downloaded a dataset using !wget and then joined it to their path using:

train_horse_dir = os.path.join(‘/tmp/horse-or-human/horses’)

I wanna know how this can be done in a local environment. Pls help! Link to the colab:

https://goo.gle/2YLupZ7

submitted by /u/StarLan7
[visit reddit] [comments]

Categories
Misc

[Project] Generating questions from AskReddit Dataset

Hello, I wanted to share a project I’ve been working on using a dataset that has questions from the r/AskReddit. I used the GPT-2 pretrained model and trained a model to generate questions. Some of the questions generated make no sense, and some are pretty funny. Check it out at the link below.

https://www.kaggle.com/camerinfigueroa/generate-reddit-posts-with-pretrained-gpt-2-model

submitted by /u/YodaByteRAM
[visit reddit] [comments]

Categories
Misc

Need some advice on GPU’s?

Brand new to machine learning. I followed a tutorial to build a chatbot which uses nlp to determine which response to send, it uses tensorflow/keras.

It seems to run the training part fine but when actually running the chatbot it returns errors regarding nvcuda and cudart.

I had no idea that GPU’s were relevant in machine learning. Is it something I can get around or do I need to invest in a new laptop??

My current model is MSI Modern 14 B10MW Core i3 10th Gen with an intel GPU.

Below is the code for the chatbot, not sure if it’s relevant but it does seem like if the training.py file is running the this should be fine?

Pretty confused so any help would be great.

import json import pickle import numpy as np import nltk from nltk.stem import WordNetLemmatizer import tensorflow from tensorflow import keras from keras.models import load_model lemmatizer = WordNetLemmatizer intents = json.loads(open('intents.json').read()) words = pickle.load(open('words.pkl', 'rb')) classes = pickle.load(open('classes.pkl', 'rb')) model = load_model('chatbot_model.model') def clean_up_sentence(sentence): sentence_words = nltk.word_tokenize(sentence) sentence_words = [lemmatizer.lemmatize(word) for word in sentence_words] return sentence_words def bag_of_words(sentence): sentence_words = clean_up_sentence(sentence) bag = [0] * len(words) for w in sentence_words: for i, word in enumerate(words): if word == w: bag[i] = 1 return np.array(bag) def predict_class(sentence): bow = bag_of_words(sentence) res = model.predict(np.array(bow))[0] error_threshold = 0.25 results = [[i, r] for i, r in enumerate(res) if r > error_threshold] results.sort(key=lambda x: x[1], reverse=True) return_list = [] for r in results: return_list.append({'intent' : classes[r[0]], 'probability': str(r[1])}) return return_list 

submitted by /u/Zenemm
[visit reddit] [comments]

Categories
Misc

(Help) TensorFlow mentions "HadoopFileSystem load error: libhdfs.so: cannot open shared object file" when verifying installation. Is this normal?

Hello, this is my first time using TensorFlow. I am installing it via pip (running python 3.7) using the official guide. It seems that everything has installed correctly, so I run the command to verify the installation. This returns:

2022-02-04 14:13:27.807610: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object f
ile: No such file or directory
Tensor(“Sum:0”, shape=(), dtype=float32)

Is this normal?

submitted by /u/RedditorOfRohan
[visit reddit] [comments]