Fórum Root.cz
Hlavní témata => Vývoj => Téma založeno: Wangarad 25. 12. 2019, 13:38:39
-
Zdravim.
Trosku som sa zasekol s pythonom.
Toto je funkcia ktora by mi mala zbehnut bez problemu.
def ChangeToOtherMachine(filelist,repo='TrainYourOwnYOLO',remote_machine =''):
'''
Takes a list of file_names located in a repo and changes it to the local machines file names. File must be executed from withing the repository
Example:
'/home/ubuntu/TrainYourOwnYOLO/Data/Street_View_Images/vulnerable/test.jpg'
Get's converted to
'C:/Users/Anton/TrainYourOwnYOLO/Data/Street_View_Images/vulnerable/test.jpg'
'''
filelist = [x.replace("\\","/") for x in filelist]
if repo[-1]=='/':
repo=repo[:-1]
if remote_machine:
prefix = remote_machine.replace("\\","/")
else:
prefix = ((os.getcwd().split(repo))[0]).replace("\\","/")
new_list = []
for file in filelist:
suffix = (file.split(repo))[1]
if suffix[0]=='/':
suffix = suffix[1:]
new_list.append(os.path.join(prefix,repo+'/',suffix).replace("\\","/"))
print("8888888888888888888*********************************98888888888888888888888888888888888")
print(new_list)
return new_list
https://github.com/AntonMu/TrainYourOwnYOLO/blob/master/Utils/Train_Utils.py
Mne to ale vzdy zasekne na tomto kusku kodu.
# This step makes sure that the path names correspond to the local machine
# This is important if annotation and training are done on different machines (e.g. training on AWS)
lines = ChangeToOtherMachine(lines,remote_machine = '')
np.random.shuffle(lines)
num_val = int(len(lines)*val_split)
num_train = len(lines) - num_valhttps://github.com/AntonMu/TrainYourOwnYOLO/blob/master/2_Training/Train_YOLO.py
Skusal som zmenit ef ChangeToOtherMachine(filelist,repo='C:\YOLO\Data\Source_Images\Training_Images\vott-csv-export/',remote_machine =''): cestu ale nefunguje to.
a pritom by to malo zbehnut bez problemu skrz python Train_YOLO.py
Vie niekto poradit kde je zrada?
-
Nakopiruj sem celu chybu, indexerror znaci, ze sa pokusas pristupovat na nty prvok v poli, kde nty prvok nie je
-
Zabudol som a chybu akou to zomrie. Sorry
Traceback (most recent call last):
File "Train_YOLO.py", line 137, in <module>
lines = ChangeToOtherMachine(lines,remote_machine = '')
File "C:\Yolo\Utils\Train_Utils.py", line 150, in ChangeToOtherMachine
suffix = (file.split(repo))[1]
IndexError: list index out of range
-
To je přece jasné. split() rozdělí řetězec na 1 až n částí, tudíž IndexError při volání split()[1] znamená, že řetězec, který chceš rozdělit, neobsahuje podřetězec, který mu posíláš jako parametr 'separator'. Tzn. ten 'file' neobsahuje řetězec uložený 'repo', přestože jsi z nějakého důvodu přesvědčen, že ho obsahuje.
-
Problem je v tom ze ak to spravne chapem tak by som to mal defalultne zmenit na???
Resp. ocakavam ze pokial je
# This step makes sure that the path names correspond to the local machine
# This is important if annotation and training are done on different machines (e.g. training on AWS)
lines = ChangeToOtherMachine(lines,remote_machine = '')prazdne tak to nic ani nenacita resp. nie je potreba.
-
Máš to v docstringu té funkce. Jak tě napadlo dát jako repo celou cestu.
def ChangeToOtherMachine(filelist,repo='TrainYourOwnYOLO',remote_machine =''):
'''
Takes a list of file_names located in a repo and changes it to the local machines file names. File must be executed from withing the repository
Example:
'/home/ubuntu/TrainYourOwnYOLO/Data/Street_View_Images/vulnerable/test.jpg'
Get's converted to
'C:/Users/Anton/TrainYourOwnYOLO/Data/Street_View_Images/vulnerable/test.jpg'
'''Takže v data_train.txt (nebo jiném souboru určeném parametrem --annotation_file), kerý se načte do lines, budeš mít cesty a parametr repo určuje repo.
-
tecka: vies ze ani neviem. To je blbost
V tom pripade by mal bez problemu nacitat obsah s data_train.txt ale s nieakeho dovodu sa tomu tak nedeje.
-
Už to napsal Ink. Pokud list vrácený splitem nemá druhý prvek (index 1), tak v tom splitovaném řetězci (cestě) prostě není ten požadovaný oddělovač (repo). Tak to zkontroluj.