Categories
Mastering Development

TRANSIENT_ERROR for TPU in Google Colab

I’m trying to run a lrcn keras model on TPUs with tensorflow 2.0. The model and generator work on CPU/GPU but I included them for reference. I also initialize the TPU and it is visible and everything looks good except for when I run .fit(): def frame_generator(self, batch_size, train_test, data_type): “””Return a generator that we […]

Categories
Artificial Intelligence (AI) Development

Trouble with EarlyStopping in tf.keras

I am training my first transferred learning model(yay!) and I am having trouble getting the model to stop training when the validation loss hasn’t changed by more than 0.1 in more than 3 epochs. Here is the relevant block of code early_stopping = tf.keras.callbacks.EarlyStopping(monitor=’val_loss’, patience=3, min_delta = 0.1) model.compile(optimizer=’adam’, loss=’sparse_categorical_crossentropy’, metrics=[‘accuracy’], callbacks=[early_stopping]) EPOCHS = 100 […]

Categories
Artificial Intelligence (AI) Development

Is it possible to convert Neural Network code in Python into Matlab code?

I want to convert the code written in Python into Matlab code. May I know is it possible to do that. Share the available ways or methods to do the conversion. May I know is there any Online Translators which do the same. Here is the Data I used: https://drive.google.com/open?id=1GLm87-5E_6YhUIPZ_CtQLV9F9wcGaTj2 Here is my code in […]

Categories
Development

how to reshape input image array from 1d to 3d

I have built the image classifier as bellow: import tensorflow as tf from tensorflow.keras.applications.mobilenet import preprocess_input image_width, image_height = 224, 224 input_shape = (image_width, image_height, 3) self.model = tf.keras.Sequential() pretrained_layer = tf.keras.applications.mobilenet.MobileNet( weights=”imagenet”, include_top=False, input_shape=self.input_shape ) self.model.add(pretrained_layer) self.model.add(tf.keras.layers.GlobalAveragePooling2D()) self.model.add(tf.keras.layers.Dense(256, activation=”relu”)) self.model.add(tf.keras.layers.Dropout(0.5)) self.model.add(tf.keras.layers.Dense(128, activation=”relu”)) self.model.add(tf.keras.layers.Dropout(0.2)) self.model.add(tf.keras.layers.Dense(len(DATA_LABELS), activation=”sigmoid”)) self.model.compile( optimizer=tf.keras.optimizers.Adam(0.0005), loss=”binary_crossentropy”, metrics=[“accuracy”], ) I also had a […]

Categories
Development

How to sovle audio signal problem by using 1D conv neural network in keras

I have a dataset (it is given and not a problem). all_speakers = np.unique([os.path.basename(i).split(‘_’)[1] for i in fsdd]) np.random.shuffle(all_speakers) train_speakers = all_speakers[:2] test_speakers = all_speakers[2:] print(“All speakers:”, all_speakers) print(“Train speakers:”, train_speakers) print(“Test speakers:”, test_speakers) train_files = [ i for i in fsdd if os.path.basename(i).split(‘_’)[1] in train_speakers ] test_files = [i for i in fsdd if […]

Categories
Artificial Intelligence (AI) Development

Applying Machine Learning to 2D Laser Scanner Data

We are using 2D Laser Scanner to scan various objects of different geometric shapes for e.g. cylinder, spiked, cylinder with notch, cylinder with curved edges e.t.c. The dataset contains points in the format [x, y] with the dimension of 1 complete scan being 160×2. The goal is to use these scan points to classify the […]

Categories
Development

Keras No data provided for “

I’m getting the following error (the one in the title) and I couldn’t find any questions on stackoverflow that resolve my issue, I’m including the code below: def build_model(embed_df,ohe_df): models= [] inputs = [] for col in embed_df: vocab_size = embed_df[col].nunique() input1 = tf.keras.layers.Input(shape=(1,),name=’embed’+’_’+col) inputs.append(input1) embed1 = tf.keras.layers.Embedding(vocab_size,200,\ trainable=True,embeddings_initializer=’uniform’)(input1) embed_rehsaped =tf.keras.layers.Reshape(target_shape=(200,))(embed1) models.append(embed_rehsaped) #input2 = tf.keras.layers.Input(shape=(len(ohe_df)),\ […]

Categories
Development

I get Very Different result by keras_metrics and sklearn.metrics

I am trying to classify text data. I am using keras_metrics to get precision, recall and f1 score. Here is my architecure code model = Sequential() model.add(Embedding(input_dim=500,output_dim=50,input_length=280)) model.add(Bidirectional(CuDNNLSTM(32, return_sequences = True))) model.add(GlobalMaxPool1D()) model.add(Dense(20, activation=”relu”)) model.add(Dropout(0.05)) model.add(Dense(1, activation=”sigmoid”)) model.compile(loss=’binary_crossentropy’, optimizer=’adam’, metrics=[‘accuracy’,km.binary_precision()]) model.fit(sequences_matrix,y_train,batch_size=128,epochs=10, validation_split=0.2,verbose=2) When i check it on test data, using following code test_sequences = tokenize.texts_to_sequences(corpus_test) […]

Categories
Development Python

Python3 Flask asyncio subprocess in route hangs

I’m using Flask 1.0.2 with Python 3.6 on Ubuntu 18.04. My app should use asyncio and asyncio.create_subprocess_exec() to lauch a background script, read stdout from it, and then return status when the script is done. I am basically trying to implement an answer from this post: Non-blocking read on a subprocess.PIPE in python The script […]

Categories
Development

Setting the learning rate in convolutional neural network

I am using google collab to learn some CNN’s. I am using model.compile() to set my loss and optimizer function. Where do I alter learning rate in the following code? model.compile(optimizer=’adam’, loss=’sparse_categorical_crossentropy’, metrics=[‘accuracy’])