official module in tensorflow examples at tensorflow.org - python

I've been following a tensorflow tutorial https://www.tensorflow.org/official_models/fine_tuning_bert
In the first code snippet, I saw a lot of imports from official module
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_datasets as tfds
tfds.disable_progress_bar()
from official.modeling import tf_utils
from official import nlp
from official.nlp import bert
# Load the required submodules
import official.nlp.optimization
import official.nlp.bert.bert_models
import official.nlp.bert.configs
import official.nlp.bert.run_classifier
import official.nlp.bert.tokenization
import official.nlp.data.classifier_data_lib
import official.nlp.modeling.losses
import official.nlp.modeling.models
import official.nlp.modeling.networks
And problem is that i found no module name official.
I guess this official module somehow related to problem specific or for BERT model(from tf-hub).
As bert model uses specific text preprocessing and official module is providing this.
So, where i can find, download, use and make imports from this official module to work? I've been using python 3.7, tf-2.2, tf-hub-0.8.0
Please help me out

The official modules of TensorFlow can be found in the TensorFlow Model Garden Repository

Related

Import Error : Not able to use keras_applications on Mac M1

Code
from keras_applications import imagenet_utils as utils
from keras_applications import correct_pad
Error
import keras
from keras_applications import vgg16
Or, preferably, this equivalent formulation:
from keras import applications
Approaches Used
I have already imported keras at the top and am also using tensorflow-macos version for Mac M1.
I have also tried to manually set the _KERAS_BACKEND = 'tensorflow' in the __init__.py of the keras_applications library in the lib folder but this is not working for some reason.

tensorflow keras import issues when loading retinanet model

%matplotlib inline
%load_ext autoreload
%autoreload 2
# external modules
from tensorflow import keras
from keras_retinanet import models
from keras_retinanet.utils.image import read_image_bgr, preprocess_image, resize_image
from keras_retinanet.utils.visualization import draw_box, draw_caption
from keras_retinanet.utils.colors import label_color
from keras_retinanet.utils.gpu import setup_gpu
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import cv2
import os
import numpy as np
import time
import csv
import math
import utm
import shapefile
import scipy
from scipy.spatial import distance
from urllib.request import urlopen
# internal modules
from utils import *
# set file path
root = os.getcwd()
rcnn_model_root = os.path.join(root, "trained_models")
input_gsv_root = os.path.join(root, "input_gsv")
output_gsv_root = os.path.join(root, "output_gsv")
output_shp_root = os.path.join(root, "output_shp")
rcnn_model_name = "resnet101_csv_25_inference.h5"
rcnn_model_path = os.path.join(rcnn_model_root,rcnn_model_name)
model = models.load_model(rcnn_model_path)
Every time I try to run this code I get issues with keras/tensorflow imports.
AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
I was told to do from keras import tensorflow or something like that, but then I get other issues like not recognizing Freeze. This was run by someone else with a specific configuration, so downgrading packages has not worked.
keras_retinanet repository is deprecated to access from newer versions of Tensorflow.
However you can access this repository in tensorflow 2.3.0 and keras 2.4 by using below code.
!pip install tensorflow==2.3.0
!pip install keras==2.4
!pip install keras_retinanet
Please find this link to get more details on keras_retinanet repository.

ImportError: cannot import name 'MarianMTModel'

import numpy as np
import torch
import torchvision
from transformers import MarianTokenizer, MarianMTModel
from typing import List
I'm getting
ImportError: cannot import name 'MarianMTModel'
I've already installed transformers. What can I do to solve this issue?
Edit : Does this import Marian model implemented in C++?

ModuleNotFoundError: No module named 'modeling'

I'm very new to deep learning and python and I'm trying to recreate the project at https://github.com/Nagakiran1/Extending-Google-BERT-as-Question-and-Answering-model-and-Chatbot
As I saw that in the project there is a file named Bert_QuestionAnswer.ipynb and with data.txt are the only difference I see from the original Bert repository, I just simply loaded it in my google drive and opened it as a notebook to see it in use.
When I run the first portion dough I get the ModuleNotFoundError: No module named 'modeling'errror.
What library is it part of?
For somoebody this was the problem :
It looks like it's trying to import from the github repo source rather
than the pip package.
If you are running this in a directory that contains the BERT github
repo, try running it elsewhere.
As always many thanks for the help.
This is the code of the file that throws me the error :
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from IPython.core.debugger import set_trace
import collections
import json
import math
import os
import random
import modeling
import optimization
import tokenization
import six
import os
import tensorflow as tf
import logging
logging.getLogger('tensorflow').disabled = True
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import warnings
warnings.filterwarnings("ignore")
import time
from pandas import Series
from nltk.tokenize import sent_tokenize
import gensim.downloader as api
from gensim.parsing.preprocessing import remove_stopwords
word_vectors = api.load("glove-wiki-gigaword-100") # load pre-trained word-vectors from gensim-data
You need to tell python where this module is:
import sys
sys.path.append("/path/to/your/bert/repo")
Because python will search in his system folders and in the current working directory. If you don't run it in the repo, python doesn't find this module.

AttributeError: module 'utils' has no attribute 'load_data'

I am engaging a project now, and the library utils might be frequently used. However, I encounter a problem
import numpy as np
import pandas as pd
import featuretools as ft
import utils
data_path = 'dataturbo/train_FD003.txt'
data = utils.load_data(data_path)
data.head()
how to solve this guys, i'm always encountering this problem
For those who wants to know the solution. I believe he is testing a package from FeatureTools.
https://github.com/Featuretools/predict-remaining-useful-life
import utils package is not something you install from conda or pip install, but a utils.py script you can download from FeatureTools github page.

Categories