It is going to be a big year for us at Oracle Code One and Oracle OpenWorld this year. The co-located developer and user conferences take place September 16-19 in San Francisco. If you haven't registered, you can still do so here. Registering for either Code One or Oracle OpenWorld gets you access t...
Posted by: xSicKxBot - 11-27-2022, 02:50 AM - Forum: Python
- No Replies
TensorFlow ModuleNotFoundError: No Module Named ‘utils’
5/5 – (1 vote)
Problem Formulation
Say, you try to import label_map_util from the utils module when running TensorFlow’s object_detection API. You get the following error message:
>>> from utils import label_map_util
Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> from utils import label_map_util
ModuleNotFoundError: No module named 'utils'
Question: How to fix the ModuleNotFoundError: No module named 'utils'?
Solution Idea 1: Fix the Import Statement
The most common source of the error is that you use the expression from utils import <something> but Python doesn’t find the utils module. You can fix this by replacing the import statement with the corrected from object_detection.utils import <something>.
For example, do not use these import statements:
from utils import label_map_util
from utils import visualization_utils as vis_util
Instead, use these import statements:
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
Everything remains the same except the bolded text.
This, of course, assumes that Python can resolve the object_detection API. You can follow the installation recommendations here, or if you already have TensorFlow installed, check out the Object Detection API installation tips here.
Solution Idea 2: Modify System Path
Another idea to solve this issue is to append the path of the TensorFlow Object Detection API folder to the system paths so your script can find it easily.
To do this, import the sys library and run sys.path.append(my_path) on the path to the object_detection folder that may reside in /home/.../tensorflow/models/research/object_detection, depending on your environment.
I don’t recommend using this approach but I still want to share it with you for comprehensibility. Try copying the utils folder from models/research/object_detection in the same directory as the Python file requiring utils.
Solution Idea 4: Import Module from Another Folder (Utils)
This is a better variant of the previous approach: use our in-depth guide to figure out a way to import the utils module correctly, even though it may reside on another path. This should usually do the trick.
Resources: You can find more about this issue here, here, and here. Among other sources, these were also the ones that inspired the solutions provided in this tutorial.
Thanks for reading this—feel free to learn more about the benefits of a TensorFlow developer (we need to keep you motivated so you persist through the painful debugging process you’re currently in).
We are welcoming everyone to join our discord[discord.gg]. We are more active there on finding giveaways, small or large, and there are daily raffles you can participate.
Posted by: xSicKxBot - 11-27-2022, 02:50 AM - Forum: Lounge
- No Replies
Get Pokemon-Themed Switch Hori Controller At A Nice Discount
If you're a Pokemon fan looking to deck out your Nintendo Switch, the Hori Split Pad Pro Pokemon Arceus Edition is $50 instead of $60 right now at Amazon.
Worlds collide in Sonic the Hedgehog's newest adventure. Accelerate to new heights and experience the thrill of high velocity open-zone freedom. Battle powerful enemies as you speed through the Starfall Islands - landscapes brimming with dense forests, overflowing waterfalls, sizzling deserts and more.
Advanced Management Console (AMC) 2.14 Release is Now Available
The Advanced Management Console (AMC) 2.14 release is now available. This release of AMC 2.14 is a documentation and bug fix release. AMC 2.14 is a commercial product licensed as part of Java SE Advanced, SE Advanced Suite and Java SE Subscriptions. The Advanced Management Console is available to cu...
Posted by: xSicKxBot - 11-26-2022, 06:39 AM - Forum: Python
- No Replies
Python | Split String and Count Results
Rate this post
Summary: Split the string using split and then use len to count the results.
Minimal Example
print("Result Count: ", len('one,two,three'.split(',')))
# Result Count: 3
Problem Formulation
Problem: Given a string. How will you split the string and find the number of split strings? Can you store the split strings into different variables?
Example
# Given String
text = '366NX-BQ62X-PQT9G-GPX4H-VT7TX'
# Expected Output:
Number of split strings: 5
key_1 = 366NX
key_2 = BQ62X
key_3 = PQT9G
key_4 = GPX4H
key_5 = VT7TX
In the above problem, the delimiter used to split the string is “-“. After splitting five substrings can be extracted. Therefore, you need five variables to store the five substrings. Can you solve it?
Solution
Splitting the string and counting the number of results is a cakewalk. All you have to do is split the string using the split() function and then use the len method upon the resultant list returned by the split method to get the number of split strings present.
Code:
text = '366NX-BQ62X-PQT9G-GPX4H-VT7TX'
# splitting the string using - as separator
res = text.split('-')
# length of split string list
x = len(res)
print("Number of split strings: ", x)
Approach 1
The idea here is to find the length of the results and then use this length to create another list containing all the variable names as items within it. This can be done with a simple for loop.
Now, you have two lists. One that stores the split strings and another that stores the variable names that will store the split strings.
So, you can create a dictionary out of the two lists such that the keys in this dictionary will be the items of the list containing the variable names and the values in this dictionary will be the items of the list containing the split strings. Read: How to Convert Two Lists Into A Dictionary
Code:
text = '366NX-BQ62X-PQT9G-GPX4H-VT7TX'
# splitting the string using - as separator
res = text.split('-')
# length of split string list
x = len(res) # Naming and storing variables and values
name = []
for i in range(1, x+1): name.append('key_'+str(i)) d = dict(zip(name, res))
for key, value in d.items(): print(key, "=", value)
Approach 2
Almost all modules have a special attribute known as __dict__ which is a dictionary containing the module’s symbol table. It is essentially a dictionary or a mapping object used to store an object’s (writable) attributes.
So, you can create a class and then go ahead create an instance of this class which can be used to set different attributes. Once you split the given string and also create the list containing the variable names (as done in the previous solution), you can go ahead and zip the two lists and use the setattr() method to assign the variable and their values which will serve as the attributes of the previously created class object. Once, you have set the attributes (i.e. the variable names and their values) and attached them to the object, you can access them using the built-in __dict__ as object_name.__dict__
Code:
text = '366NX-BQ62X-PQT9G-GPX4H-VT7TX'
# splitting the string using - as separator
res = text.split('-')
# length of split string list
x = len(res)
print("Number of split strings: ", x) # variable creation and value assignment
name = []
for i in range(1, x + 1): name.append('key_' + str(i)) class Record(): pass r = Record() for name, value in zip(name, res): setattr(r, name, value)
print(r.__dict__) for key, value in r.__dict__.items(): print(key, "=", value)
Approach 3
Caution: This solution is not recommended unless this is the only option left. I have mentioned this just because it solves the purpose. However, it is certainly not the best way to approach the given problem.
Code:
text = '366NX-BQ62X-PQT9G-GPX4H-VT7TX'
# splitting the string using - as separator
res = text.split('-')
# length of split string list
x = len(res)
print("Number of split strings: ", x)
name = []
for i in range(1, x + 1): name.append('key_' + str(i)) for idx, value in enumerate(res): globals()["key_" + str(idx + 1)] = value
print(globals())
x = 0
for i in reversed(globals()): print(i, "=", globals()[i]) x = x+1 if x == 5: break
Explanation: globals() function returns a dictionary containing all the variables in the global scope with the variable names as the key and the value assigned to the variable will be the value in the dictionary. You can reference this dictionary and add new variables by string name (globals()['a'] = 'b' sets variable a equal to "b"), however this is generally a terrible thing to do.
Since global returns a dictionary containing all the variables in the global scope, a workaround to get only the variables we assigned is to extract the last “N” key-value pairs from this dictionary where “N” is the length of the split string list.
Conclusion
I hope the solutions mentioned in this tutorial have helped you. Please stay tuned and subscribe for more interesting reads and solutions in the future. Happy coding!
Hi all! Starting from this week we will give you regular updates on the Vorax development every friday.
Below are our most recent YouTube videos that will give you an idea of where Vorax is in development.
Video 1: Ambush
Vorax is for the most part an open world game where you've got miles and miles to freely explore to your heart's content. However there are also some more tightly closed spaces, claustrophobic even, like tunnels, sewers and caves. There the mutation has peculiar aspects depending on the environment. Certain kind of monsters are adapting to certain type of conditions, such as light or air, therefore some types of mutations will be specific to closed and dark spaces.
Video 2: Defending The House
The majority of the enemies, especially the toughest are photosensitive. You must balance your physical safety and your mental sanity carefully. Finding a shelter, an appropriate location where you can hide and barricade yourself will protect you, but staying too much into the darkness will slowly chip away at your sanity. Turning on the light might offer some mental comfort, however that will also, potentially, attract unwelcomed guests.
In fact, at night the hostile creatures, mostly photosensitive, come out to hunt. So you need to exercise extreme caution when moving around. We have planned several buildings that can be cleared, reinforced and made into a relatively safe haven for the night. But if these safety operations are not carried out, they can be attacked by creatures.
Video 3: Tunnel
The virus contaminates the whole island, resulting in various forms of aberrations, from small to big... to massive. What delves deep in the dark tunnels is just one of those aberrations. Dealing with it might make both your heart and the ground beneath you tremble.
Our Vision.
We have been trying for months to work on a large game area (in the alpha indiegala for now only 15% of the island is explorable) where we want to give the feeling of a whole environment, flora, fauna, human beings… every cell contaminated by the virus. Because the pathogen does not affect humans exclusively, other 'entities' might be infected by the virus and the resulting mutations can be abnormal.
We also focused heavily on combat system, an aspect that had left us unsatisfied in our previous title, Die Young. The team has placed a big emphasison ranged weapons and firearms, which is why managing the limited ammunition available will be important to survive. But we haven't neglected hand-to-hand combat either. In the coming weeks we will see the use of different work tools that can turn into lethal weapons.
Compared to Die Young we think we've definitely improved the survival side. You will be able to craft almost anything you can find in the game and also you will be able to build a large variety of structures in order to have the most personalized gaming experience possible.
Let's keep in touch next friday.
Keep an eye on ig for updates, especially next week. On the Black Friday weekend you will be able to try out the UPDATED ALPHA[freebies.indiegala.com] build. Once more, for a limited time only. Next weekend, infact, we will update to latest features and fixes we've been working so hard in those months.
Make sure to join us on Discord[discord.gg] for exclusive news.
❤️ STAR WARS™: Squadrons Store Page[store.epicgames.com]
The game is free to keep if claimed by Thursday, 1st December 2022 16:00 UTC
Next weeks freebies: Fort Triumph
We are welcoming everyone to join our discord[discord.gg]. We are more active there on finding giveaways, small or large, and there are daily raffles you can participate.