I am working on a project that detects handwritten characters. There are many packages I have imported. One of the package keras.models.load_model(mnist.h5) is throwing following error:
OSError: Unable to open file (unable to open file: name = 'mnist.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
Code Snippet is:
from keras.models import load_model
from tkinter import *
import tkinter as tk
import win32gui
from PIL import ImageGrab, Image
import numpy as np
model = load_model('mnist.h5')
Using Python 3.7
Can anyone please help me.
Thank you
Please refer working code to import the Mnist data set.
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
print(tf.__version__)
#### Import the Fashion MNIST dataset
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
Related
pip install -q hvplot
import pandas as pd
import numpy as np
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
import hvplot.pandas
from sklearn.model_selection import train_test_split, RandomizedSearchCV
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import (
accuracy_score, confusion_matrix, classification_report,
roc_auc_score, roc_curve, auc,
plot_confusion_matrix, plot_roc_curve
)
from xgboost import XGBClassifier
from sklearn.ensemble import RandomForestClassifier
import tensorflow as tf
from tensorflow.keras.models import Sequential, Model
from tensorflow.keras.layers import Dense, Dropout, BatchNormalization
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import AUC
pd.set_option('display.float', '{:.2f}'.format)
pd.set_option('display.max_columns', 50)
pd.set_option('display.max_rows', 50)
I'm trying to run a code from Kaggle.
https://www.kaggle.com/code/faressayah/lending-club-loan-defaulters-prediction
However, I was stuck in the first few steps, which are the code lines above. I've spent hours on this and can't figure it out. I got the following error message
Does anyone know how to fix this? Thank you very much for helping out!
Running below code gave the error as AttributeError: module 'tensorflow.compat.v2.tpu.experimental' has no attribute 'HardwareFeature'
import os
import pprint
import tempfile
from typing import Dict, Text
import numpy as np
import pandas as pd
import tensorflow as tf
import tensorflow_datasets as tfds
!pip install -q tensorflow-recommenders
import tensorflow_recommenders as tfrs
tensorflow version used was 2.9.1 and the code was run from Google Colab
Did a trial and error changed the order of execution as below and it worked fine no errors this time
!pip install -q tensorflow-recommenders
import os
import pprint
import tempfile
from typing import Dict, Text
import numpy as np
import pandas as pd
import tensorflow as tf
import tensorflow_datasets as tfds
import tensorflow_recommenders as tfrs
I am working in colab to test a code. While importing models, its giving error No module named 'efficientnet'
I am sharing the code and error here.
# for accessing tabular data
import pandas as pd
import numpy as np
import os
os.chdir('/content/drive/My Drive/')
# adding classweight
from sklearn.utils import class_weight
# Evaluation Metric
from sklearn.metrics import cohen_kappa_score
from sklearn.metrics import confusion_matrix, precision_score, recall_score
# for visualization
import cv2
import matplotlib.pyplot as plt
import seaborn as sns
from prettytable import PrettyTable
# backend
import keras
from keras import backend as K
import tensorflow as tf
from keras.callbacks import Callback
# for transfer learning
from tensorflow.keras.applications import VGG16, VGG19
from tensorflow.keras.applications import DenseNet121
from tensorflow.keras.applications import ResNet50, ResNet152
from tensorflow.keras.applications import InceptionV3
from efficientnet.keras import EfficientNetB0, EfficientNetB3, EfficientNetB4
from keras.applications import Xception
# for model architecture
from keras.models import Sequential
from keras.layers import GlobalAveragePooling2D, Dropout, Dense, Conv2D, MaxPooling2D, Activation, Flatten
# for Tensorboard visualization
from keras.callbacks import TensorBoard
# for Data Augmentation
from keras.preprocessing.image import ImageDataGenerator
enter image description here
It should be,
from tensorflow.keras.applications import EfficientNetB0, EfficientNetB3, EfficientNetB4
I have been working on this image classification(watermark detection) assignment
I am trying to load a folder of images
from keras.preprocessing.image import load_img
import cv2
import matplotlib.pyplot as plt
DATADIR = 'F:\IMP.DATA\Task\Watermark_test_data'
CATEGORIES=['Watermark','No Watermark']
for category in CATEGORIES:
path= os.path.join(DATADIR,category)#path to test folder
for img in os.listdir(path):
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show(img_array)
break
break
img = load_img('F:/IMP.DATA/Task/Watermark_test_data/Watermark/1.jpg')
print(type(img))
print(img.format)
print(img.mode)
print(img.size)
img.show()
import numpy as np
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense,Dropout,Flatten
from keras.layers.convolutional import Conv2D,MaxPooling2D
from keras.utils import np_utils
from keras import backend as K
import os
import cv2
DATADIR = 'F:\IMP.DATA\Task\Watermark_test_data'
CATEGORIES=['Watermark','No Watermark']
for category in CATEGORIES:
path= os.path.join(DATADIR,category)#path to test folder
for img in os.listdir(path):
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show(img_array)
break
break
I have been using cv2 and load_img to load the image but in both the cases I get error in matplotlib
plt.imshow (function)
This is the error that I get
File "<ipython-input-51-2b07cb64d5a1>", line 11
plt.imshow(img_array,cmap="gray")
^
SyntaxError: invalid syntax
I can't see anything wrong in the syntax
The SyntaxError is caused by a missing closing parenthesis in this line:
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
Add ) after os.path.dirname(os.path.join(path,img) to solve it.
I have a task where I am building a model and I am trying to use sequential but I ended up having an error. I am not sure what went wrong. This is just the start of the model but can't seem to work. To add more details the generator code is where I import the data and use it as an image generator. Deep code is code where I am building the model.
Deep Code:
import tensorflow as tf
from tensorflow import keras
import numpy as np
print(tf.__version__)
from generators import ImageGenerator
imagegenerator = ImageGenerator(3)
model = keras.Sequential()
model.add(Dense(32,activation='relu', input_shape=()))
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit_generator(imagegenerator,epochs=20)
generator code:
from PIL import Image, ImageDraw, ImageFont, ImageFilter
import numpy as np
import string, random
import keras
import abc
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
-----