How to define a file path when dealing with Tensorflow? - python

This issue has been solved sorry for any time wasted I'm using notepad++ due to hardware constraints so I wasn't aware of needing to import OS to define a filepath
I am trying to create a TFLite model, I have drawn an arrow to where I'm getting the file path error:
Error: (NameError: name 'oranges' is not defined)
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
import tensorflow as tf
assert tf.__version__.startswith('2')
from tensorflow_examples.lite.model_customization.core.data_util.image_dataloader import ImageClassifierDataLoader
from tensorflow_examples.lite.model_customization.core.task import image_classifier
from tensorflow_examples.lite.model_customization.core.task.model_spec import efficientnet_b0_spec
from tensorflow_examples.lite.model_customization.core.task.model_spec import ImageModelSpec
import matplotlib.pyplot as plt
data = ImageClassifierDataLoader.from_folder(oranges) <-- oranges is a folder containing the test
images. It is in the same folder as this file
model = image_classifier.create(data)
loss, accuracy = model.evaluate()
model.export('image_classifier.tflite', 'image_labels.txt')

The path must be a folder containing your images for modelling. In this case, the entry oranges is not defined as a folder path anywhere in the code.
To create a folder path, run:
import os
oranges = os.path.abspath('oranges')
Before executing the code:
data = ImageClassifierDataLoader.from_folder(oranges)

Related

No module named 'augmentations'?

I'm getting this error. It doesn't seem to find the augmentations module. I'm trying to use basicsr for model training.I already tried to install the augmentation module, albumentation, but it doesn't work.
Can someone help me and explain how to solve this?
How it's being imported:
import os.path
import random
import numpy as np
import cv2
import torch
import torch.utils.data as data
import data.util as util
import sys
sys.path.append('../codes/scripts')
sys.path.append('../codes/data')
**import augmentations # Here shows the module import error**
As it is being used below:
# Random Crop (reduce computing cost and adjust images to correct size first)
if img_HR.shape[0] > HR_size or img_HR.shape[1] > HR_size:
#Here the scale should be in respect to the images, not to the training scale (in case they are being scaled on the fly)
scaleor = img_HR.shape[0]//img_LR.shape[0]
img_HR, img_LR = augmentations.random_crop_pairs(img_HR, img_LR, HR_size, scaleor)
Console error:
File "D:\basicsrtrainmodel\BasicSR\codes\data\LRHROTF_dataset.py", line 12, in <module>
import augmentations
ModuleNotFoundError: No module named 'augmentations'
Someone help me please?

module 'keras.backend' has no attribute 'unique_object_name'

This is the error I can't figure out.
module 'keras.backend' has no attribute 'unique_object_name'
This is what I'm importing:
import cv2
import os
from keras.models import load_model
import numpy as np
from pygame import mixer
import time
I get the error when I try and run this line:
model = load_model('C:/Users/Henry/Downloads/Drowsiness detection/Drowsiness detection/models/cnnCat2.h5')
Method keras.models.load_model() probably worked properly before Keras become part of Tensorflow.
If you are using newer version of tf you should call this to load model:
tf.keras.models.load_model()

How to get Reproducible Results with AutoKeras

I need to reproduce results with AutoKeras for the same input and configurations: I tried the following at the beginning of my notebook but still didn't got the same results.
I am using Tensorflow 2.0.4 and AutoKeras 1.0.12
seed_value= 0
import os
os.environ['PYTHONHASHSEED']=str(seed_value)
os.environ['TF_CUDNN_DETERMINISTIC'] = str(seed_value)
import tensorflow as tf
tf.random.set_seed(seed_value)
from keras import backend as K
import autokeras as ak
import random
random.seed(seed_value)
import numpy as np
np.random.seed(seed_value)
Note:
I want to reproduce results at different times; i.e. to get the same result after closing the notebook, and run the code again .. not during the same session.
I guess, you need to seed the generators before each call you want to be reproducable. The best option is to make such a decorator (or a context manager):
import contextlib
#contextlib.contextmanager
def reproducable(seed_value=0):
import os
os.environ['PYTHONHASHSEED']=str(seed_value)
os.environ['TF_CUDNN_DETERMINISTIC'] = str(seed_value)
import tensorflow as tf
tf.random.set_seed(seed_value)
from keras import backend as K
import autokeras as ak
import random
random.seed(seed_value)
import numpy as np
np.random.seed(seed_value)
yield
#reproducable()
def main():
# ...put your code here...
UPD
Note: I want to reproduce results at different times; i.e. to get the same result after closing the notebook, and run the code again .. not during the same session.
and?

how can I import "Dense3D" and use it in code?

I tried to run a code from git but i found a problem with importing Dense3D.
here the part of code witch relate to the problem:
here the part of code that relate to the problem:
import torch
from torch.models import Dense3D
import torch.nn as nn
#some lines deleted
print("Loading options...")
with open(sys.argv[1], 'r') as optionsFile:
options = toml.loads(optionsFile.read())
#Create the model.
model = Dense3D(options)
it make error that "can't import Dense3D" or something like this in another tries with some changes.
and i used colab .

Dill installed - throwing error that part of the module is missing

I'm writing code in a Jupyter Notebook that involves cleaning and analyzing a large amount of consumer data. I'm trying to use dill to save the dataframes with thousands of rows so I don't have to run the code every time I want to make an adjustment, so dill seems like the perfect package to do so... Except I'm getting this error when attempting to pickle the notebook:
AttributeError: module 'dill' has no attribute 'dump_session'
Let me know if the program code is necessary - I don't think it should make a difference. The imports are:
import numpy as np
import pandas as pd
import dill
import scipy
from matplotlib import pyplot as plt
from __future__ import division
from collections import OrderedDict
from sklearn.cluster import KMeans
pd.options.display.max_columns = None
and when I run this code I get the error from above:
dill.dump_session('recengine.db')
Is there another package that's interfering with dill's use of pickle vs. cpickle?

Categories